I am using pexpect to upload a file to SFTP server. For accesssing the server first time, I get message as The authenticity of host..can't be established.Are you sure you want to continue connecting (yes/no)?
to which I want the user to interact and answer yes/no. However, when user says yes, I want the interactive mode to be off and then take the password from my script instead of prompting user. Is this possible using pexpect ?
p = spawn('XXXXXXXX')
password = 'XXXXXXXXx'
out=p.expect(['(?i)password:', '(?i)Are you sure you want to continue connecting (yes/no)?']
if out == 1:
p.interact()
# Script should continue to send password and upload file
But this goes into interactive mode and doesn't come back to script
Pls. note - I run this python script in my terminal.
If not pexpect, pls.propose a solution not based on paramiko, pysftp
from Switch between interactive and non-interactive mode in pexpect
No comments:
Post a Comment