[Tutor] sftp using subprocess
David Rock
david at graniteweb.com
Mon Dec 3 19:12:05 EST 2018
> On Dec 3, 2018, at 16:01, Asad <asad.hasan2004 at gmail.com> wrote:
>
> Hi All ,
>
> I am looking for a solution to automate downloading file using sftp
> process using :
>
> batch.txt :contains the following two lines
> cd 12345678
> get 12345678_1.zip
>
>
> import subprocess
> host="abc.com"
> user="sa"
> user_host="%s@%s" % (user, host)
> sftp_process = subprocess.Popen(['sftp', '-b', 'batch.txt', user_host],
> shell=False)
>
> however it gives error even unable to provide password .
batch mode for sftp assumes you don’t need a password. From the manage:
-b batchfile
Batch mode reads a series of commands from an input batchfile instead of stdin.
Since it lacks user interaction it should be used in conjunction with non-inter‐
active authentication.
You would need to set up an ssh key with a null passphrase, or set up an ssh-agent in order for that to work.
Another option would be to use pexpect to automate console input
—
David Rock
david at graniteweb.com
More information about the Tutor
mailing list