From 627ac1b2d9278c70dec1d3704da01c5209d354d9 Mon Sep 17 00:00:00 2001 From: Borna Butkovic Date: Fri, 26 Mar 2021 22:13:03 +0100 Subject: [PATCH] ftp: add --ftp-ask-password to prompt for password when needed --- backend/ftp/ftp.go | 21 +++++++++++++++++---- docs/content/ftp.md | 9 +++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/backend/ftp/ftp.go b/backend/ftp/ftp.go index 11ae2764d..15cbb5260 100644 --- a/backend/ftp/ftp.go +++ b/backend/ftp/ftp.go @@ -61,7 +61,6 @@ func init() { Name: "pass", Help: "FTP password.", IsPassword: true, - Required: true, }, { Name: "tls", Help: `Use Implicit FTPS (FTP over TLS). @@ -139,6 +138,14 @@ Enabled by default. Use 0 to disable.`, Help: "Maximum time to wait for data connection closing status.", Default: fs.Duration(60 * time.Second), Advanced: true, + }, { + Name: "ask_password", + Default: false, + Help: `Allow asking for FTP password when needed. + +If this is set and no password is supplied then rclone will ask for a password +`, + Advanced: true, }, { Name: config.ConfigEncoding, Help: config.ConfigEncodingHelp, @@ -179,6 +186,7 @@ type Options struct { IdleTimeout fs.Duration `config:"idle_timeout"` CloseTimeout fs.Duration `config:"close_timeout"` ShutTimeout fs.Duration `config:"shut_timeout"` + AskPassword bool `config:"ask_password"` Enc encoder.MultiEncoder `config:"encoding"` } @@ -444,9 +452,14 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (ff fs.Fs if err != nil { return nil, err } - pass, err := obscure.Reveal(opt.Pass) - if err != nil { - return nil, fmt.Errorf("NewFS decrypt password: %w", err) + pass := "" + if opt.AskPassword && opt.Pass == "" { + pass = config.GetPassword("FTP server password") + } else { + pass, err = obscure.Reveal(opt.Pass) + if err != nil { + return nil, fmt.Errorf("NewFS decrypt password: %w", err) + } } user := opt.User if user == "" { diff --git a/docs/content/ftp.md b/docs/content/ftp.md index 587ff0fc3..85a696aab 100644 --- a/docs/content/ftp.md +++ b/docs/content/ftp.md @@ -180,6 +180,15 @@ FTP password. - Type: string - Default: "" +#### --ftp-ask-password + +Ask for password when connecting to a FTP server and no password is configured. + +- Config: ask_password +- Env Var: RCLONE_FTP_ASK_PASSWORD +- Type: bool +- Default: false + #### --ftp-tls Use Implicit FTPS (FTP over TLS).