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: check --passive-port arguments are correct

Nick Craig-Wood7d3648dc46f9
diff --git a/cmd/serve/ftp/ftp.go b/cmd/serve/ftp/ftp.go
index a2a4df159..b8022599e 100644
--- a/cmd/serve/ftp/ftp.go
+++ b/cmd/serve/ftp/ftp.go
@@ -13,6 +13,7 @@ import (
"net"
"os"
"os/user"
+ "regexp"
"strconv"
"sync"
"time"
@@ -128,6 +129,8 @@ type server struct {
useTLS bool
}
+var passivePortsRe = regexp.MustCompile(`^\s*\d+\s*-\s*\d+\s*$`)
+
// Make a new FTP to serve the remote
func newServer(ctx context.Context, f fs.Fs, opt *Options) (*server, error) {
host, port, err := net.SplitHostPort(opt.ListenAddr)
@@ -151,6 +154,11 @@ func newServer(ctx context.Context, f fs.Fs, opt *Options) (*server, error) {
}
s.useTLS = s.opt.TLSKey != ""
+ // Check PassivePorts format since the the server library doesn't!
+ if !passivePortsRe.MatchString(opt.PassivePorts) {
+ return nil, fmt.Errorf("invalid format for passive ports %q", opt.PassivePorts)
+ }
+
ftpopt := &ftp.ServerOpts{
Name: "Rclone FTP Server",
WelcomeMessage: "Welcome to Rclone " + fs.Version + " FTP Server",