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

This commit is contained in:
Leo R. Lundgren
2018-03-15 00:17:09 +01:00
committed by Nick Craig-Wood
parent d551137635
commit 04e055fc06
2 changed files with 23 additions and 0 deletions

View File

@@ -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,