ftp: add --ftp-ask-password to prompt for password when needed

This commit is contained in:
Borna Butkovic 2021-03-26 22:13:03 +01:00 committed by Nick Craig-Wood
parent ae395d8cf0
commit 627ac1b2d9
2 changed files with 26 additions and 4 deletions

View File

@ -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 == "" {

View File

@ -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).