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

sftp: Add --sftp-ask-password flag to prompt for password when needed - #2137

Leo R. Lundgren04e055fc0609
diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go
index 4b3c9dec5..6453a9783 100644
--- a/backend/sftp/sftp.go
+++ b/backend/sftp/sftp.go
@@ -5,6 +5,7 @@
package sftp
import (
+ "fmt"
"io"
"io/ioutil"
"os"
@@ -17,6 +18,7 @@ import (
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fs/config"
+ "github.com/ncw/rclone/fs/config/flags"
"github.com/ncw/rclone/fs/config/obscure"
"github.com/ncw/rclone/fs/fshttp"
"github.com/ncw/rclone/fs/hash"
@@ -35,6 +37,9 @@ const (
var (
currentUser = readCurrentUser()
+
+ // Flags
+ sftpAskPassword = flags.BoolP("sftp-ask-password", "", false, "Allow asking for SFTP password when needed.")
)
func init() {
@@ -331,6 +336,13 @@ func NewFs(name, root string) (fs.Fs, error) {
sshConfig.Auth = append(sshConfig.Auth, ssh.Password(clearpass))
}
+ // Ask for password if none was defined and we're allowed to
+ if pass == "" && *sftpAskPassword {
+ fmt.Fprint(os.Stderr, "Enter SFTP password: ")
+ clearpass := config.ReadPassword()
+ sshConfig.Auth = append(sshConfig.Auth, ssh.Password(clearpass))
+ }
+
f := &Fs{
name: name,
root: root,
diff --git a/docs/content/sftp.md b/docs/content/sftp.md
index 6dab5afb5..fa79f2ae2 100644
--- a/docs/content/sftp.md
+++ b/docs/content/sftp.md
@@ -127,6 +127,9 @@ instance `/home/$USER/.ssh/id_rsa`.
If you don't specify `pass` or `key_file` then rclone will attempt to
contact an ssh-agent.
+If you set the `--sftp-ask-password` option, rclone will prompt for a
+password when needed and no password has been configured.
+
### ssh-agent on macOS ###
Note that there seem to be various problems with using an ssh-agent on
@@ -141,6 +144,14 @@ And then at the end of the session
These commands can be used in scripts of course.
+### Specific options ###
+
+Here are the command line options specific to this remote.
+
+#### --sftp-ask-password ####
+
+Ask for the SFTP password if needed when no password has been configured.
+
### Modified time ###
Modified times are stored on the server to 1 second precision.