"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
sftp: defer asking for user passwords until the SSH connection succeeds Issue: 4660 https://github.com/rclone/rclone/issues/4660
Stephen Harris9e925becb63a
diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.goindex 6a0ed2262..d5848b01d 100644--- a/backend/sftp/sftp.go+++ b/backend/sftp/sftp.go@@ -563,16 +563,22 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {sshConfig.Auth = append(sshConfig.Auth, ssh.Password(clearpass))}- // Ask for password if none was defined and we're allowed to+ // Config for password if none was defined and we're allowed to+ // We don't ask now; we ask if the ssh connection succeedsif opt.Pass == "" && opt.AskPassword {- _, _ = fmt.Fprint(os.Stderr, "Enter SFTP password: ")- clearpass := config.ReadPassword()- sshConfig.Auth = append(sshConfig.Auth, ssh.Password(clearpass))+ sshConfig.Auth = append(sshConfig.Auth, ssh.PasswordCallback(getPass))}return NewFsWithConnection(ctx, name, root, m, opt, sshConfig)}+// If we're in password mode and ssh connection succeeds then this+// callback is called+func getPass() (string, error) {+ _, _ = fmt.Fprint(os.Stderr, "Enter SFTP password: ")+ return config.ReadPassword(), nil+}+// NewFsWithConnection creates a new Fs object from the name and root and an ssh.ClientConfig. It connects to// the host specified in the ssh.ClientConfigfunc NewFsWithConnection(ctx context.Context, name string, root string, m configmap.Mapper, opt *Options, sshConfig *ssh.ClientConfig) (fs.Fs, error) {