I need to login to a unixserver using the python package paramiko. Then from teh unix server, issue an sftp command to a second server. Then navigate to a directory on the second server and capture the directory listing.
SO I try the below but my script just hangs. I imagine it issues the sftp command but waits for user input?:
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
host_name = host_name
#First connection
ssh_client.connect(host_name, username=some_user,password=passwd)
ssh_client.get_transport().is_active()
#This issues an sftp from teh unix host and captures the output
def confirm_file_transfer():
cmd1 = 'sftp -oIdentityFile=RSA_FILE_NAME sftp_user@sftp_host && cd sent && ls -l && exit'
stdin, stdout, stderr = ssh_client.exec_command(cmd1)
print("\nOutput for ", datetime.now())
print("\n{}".format('\n'.join(stdout.readlines())))
confirm_file_transfer()