[Tutor] sftp using subprocess

Mats Wichmann mats at wichmann.us
Tue Dec 4 17:49:41 EST 2018


On 12/4/18 2:44 PM, David Rock wrote:
> 
>> On Dec 4, 2018, at 15:37, Alan Gauld via Tutor <tutor at python.org> wrote:
>>
>> On 04/12/2018 18:30, David Rock wrote:
>>> you MUST stop trying to use batch mode, because it will never work.
>>
>> But you could presumably use interactive mode via Popen
>> by taking control of the stdin/out pipes.
>>
>> But then you are basically re writing expect!
> 
> Right.  and what’s worse, sftp doesn’t like here documents (by design, for fairly obvious reasons).  The best option (if it’s possible) really is setting up ssh key authentication.

yes, programs which need to prompt for a secret are intentionally
paranoid and hard to work with programmatically. often they flush the
input stream before prompting, so you have to synchronize things across
your pipe to get it to work. it's certainly a reason a program like
expect is non-trivial. you're really better off not trying to reinvent
this logic, as experts have spent a lot of time getting it to work
safely and correctly.

"I am sure someone would have cracked this problem earlier if they can
share the code".  Yup.  The problem is you're telling us you're not
allowed to use the solutions that exist - I presume if pexpect is out,
then other things will be as well?

Here's a project you could look at, though I'm expecting you can't use
it either...

https://bitbucket.org/dundeemt/pysftp/overview




More information about the Tutor mailing list