[Tutor] sftp using subprocess

David Rock david at graniteweb.com
Tue Dec 4 12:36:17 EST 2018


> On Dec 4, 2018, at 02:41, Alan Gauld via Tutor <tutor at python.org> wrote:
> 
> On 04/12/2018 06:25, Asad wrote:
> 
>> Permission denied (keyboard-interactive,publickey,password).
>> Connection closed
>> 
>> Is there any other way to acheive this because I cannot import pexcept
>> module .
> 
> That looks like the problem that David already highlighted
> with sftp.

Yup.  So, back to my other question regarding ssh key access…

Do you have the ability to ssh to an account on the target system (i.e., use ssh to log in, not use sftp to grab a file)?
If you do, then the “easiest” solution is to create an ssh key and set up passwordless authentication.  If you do not, then maybe you can upload the key through some web service.  What is the actual target system to which you are trying to connect?  Is there an admin that can help configure ssh key-based access for you?

If you can’t set up key access, then you will need to automate sending the login information (hence the pexpect recommendation, since this is a python list, after all).  If you can’t install pexpect, you may have expect available (on what OS are you running your script?); but writing an expect script is starting to drift away from a python tutor list a bit.

If you are on linux, you may want to forego python altogether if you can’t get the ssh key access enabled and use a bash here document for automation.  
http://www.tldp.org/LDP/abs/html/here-docs.html

The disadvantage to this (and to using expect, for that matter) is plaintext storage of credentials on your system, but it’s pretty simple to use.


— 
David Rock
david at graniteweb.com






More information about the Tutor mailing list