如何解决Python paramiko 使用 ssh 连接,然后使用 sftp
我需要使用 python 包 paramiko 登录到 unixserver。然后从 teh unix 服务器,向第二台服务器发出 sftp 命令。然后导航到第二台服务器上的目录并捕获目录列表。
所以我尝试以下操作,但我的脚本挂起。我想它发出 sftp 命令但等待用户输入?:
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()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。