Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

serve ftp: convert options to new style

Nick Craig-Wood58da1a165cc3
diff --git a/cmd/serve/ftp/ftp.go b/cmd/serve/ftp/ftp.go
index 9aecfea24..5e864aaf8 100644
--- a/cmd/serve/ftp/ftp.go
+++ b/cmd/serve/ftp/ftp.go
@@ -25,7 +25,6 @@ import (
"github.com/rclone/rclone/fs/config/flags"
"github.com/rclone/rclone/fs/config/obscure"
"github.com/rclone/rclone/fs/log"
- "github.com/rclone/rclone/fs/rc"
"github.com/rclone/rclone/vfs"
"github.com/rclone/rclone/vfs/vfscommon"
"github.com/rclone/rclone/vfs/vfsflags"
@@ -34,40 +33,55 @@ import (
ftp "goftp.io/server/v2"
)
+// OptionsInfo descripts the Options in use
+var OptionsInfo = fs.Options{{
+ Name: "addr",
+ Default: "localhost:2121",
+ Help: "IPaddress:Port or :Port to bind server to",
+}, {
+ Name: "public_ip",
+ Default: "",
+ Help: "Public IP address to advertise for passive connections",
+}, {
+ Name: "passive_port",
+ Default: "30000-32000",
+ Help: "Passive port range to use",
+}, {
+ Name: "user",
+ Default: "anonymous",
+ Help: "User name for authentication",
+}, {
+ Name: "pass",
+ Default: "",
+ Help: "Password for authentication (empty value allow every password)",
+}, {
+ Name: "cert",
+ Default: "",
+ Help: "TLS PEM key (concatenation of certificate and CA certificate)",
+}, {
+ Name: "key",
+ Default: "",
+ Help: "TLS PEM Private key",
+}}
+
// Options contains options for the http Server
type Options struct {
//TODO add more options
- ListenAddr string // Port to listen on
- PublicIP string // Passive ports range
- PassivePorts string // Passive ports range
- BasicUser string // single username for basic auth if not using Htpasswd
- BasicPass string // password for BasicUser
- TLSCert string // TLS PEM key (concatenation of certificate and CA certificate)
- TLSKey string // TLS PEM Private key
-}
-
-// DefaultOpt is the default values used for Options
-var DefaultOpt = Options{
- ListenAddr: "localhost:2121",
- PublicIP: "",
- PassivePorts: "30000-32000",
- BasicUser: "anonymous",
- BasicPass: "",
+ ListenAddr string `config:"addr"` // Port to listen on
+ PublicIP string `config:"public_ip"` // Passive ports range
+ PassivePorts string `config:"passive_port"` // Passive ports range
+ BasicUser string `config:"user"` // single username for basic auth if not using Htpasswd
+ BasicPass string `config:"pass"` // password for BasicUser
+ TLSCert string `config:"cert"` // TLS PEM key (concatenation of certificate and CA certificate)
+ TLSKey string `config:"key"` // TLS PEM Private key
}
// Opt is options set by command line flags
-var Opt = DefaultOpt
+var Opt Options
// AddFlags adds flags for ftp
func AddFlags(flagSet *pflag.FlagSet) {
- rc.AddOption("ftp", &Opt)
- flags.StringVarP(flagSet, &Opt.ListenAddr, "addr", "", Opt.ListenAddr, "IPaddress:Port or :Port to bind server to", "")
- flags.StringVarP(flagSet, &Opt.PublicIP, "public-ip", "", Opt.PublicIP, "Public IP address to advertise for passive connections", "")
- flags.StringVarP(flagSet, &Opt.PassivePorts, "passive-port", "", Opt.PassivePorts, "Passive port range to use", "")
- flags.StringVarP(flagSet, &Opt.BasicUser, "user", "", Opt.BasicUser, "User name for authentication", "")
- flags.StringVarP(flagSet, &Opt.BasicPass, "pass", "", Opt.BasicPass, "Password for authentication (empty value allow every password)", "")
- flags.StringVarP(flagSet, &Opt.TLSCert, "cert", "", Opt.TLSCert, "TLS PEM key (concatenation of certificate and CA certificate)", "")
- flags.StringVarP(flagSet, &Opt.TLSKey, "key", "", Opt.TLSKey, "TLS PEM Private key", "")
+ flags.AddFlagsFromOptions(flagSet, "", OptionsInfo)
}
func init() {
diff --git a/cmd/serve/ftp/ftp_test.go b/cmd/serve/ftp/ftp_test.go
index a90744d52..b886069d9 100644
--- a/cmd/serve/ftp/ftp_test.go
+++ b/cmd/serve/ftp/ftp_test.go
@@ -33,7 +33,7 @@ const (
func TestFTP(t *testing.T) {
// Configure and start the server
start := func(f fs.Fs) (configmap.Simple, func()) {
- opt := DefaultOpt
+ opt := Opt
opt.ListenAddr = testHOST + ":" + testPORT
opt.PassivePorts = testPASSIVEPORTRANGE
opt.BasicUser = testUSER