Port forwarding and the open SFTP using Python Paramiko(使用Python Paramiko的端口转发和开放的SFTP)
本文介绍了使用Python Paramiko的端口转发和开放的SFTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用ssh在服务器上执行了命令。现在,我必须对不同的IP执行另一个ssh,同时保持旧ssh活动。
此新IP是端口转发,然后将用于执行SFTP。 我面临的问题是两个ssh连接都在同一个端口上,因此无法执行第二个ssh。 未通过SFTP。
对此的任何支持都将有所帮助。
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username=username, password=password, port=22)
time.sleep(3)
#Invoke shell to open multiple channel with in one SSH
chan = ssh.invoke_shell()
chan.send(ip1+'
')
time.sleep(5)
chan.send(pass1+'
')
time.sleep(10)
chan.send("ssh "+ip2+'
')
time.sleep(10)
chan.send(pass2+'
')
time.sleep(5)
#Execute command
chan.send(cmd)
#connect to another ip to do sftp
ssh1 = paramiko.SSHClient()
ssh1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("127.0.0.4", username=usr2, password=pass2, port=22)
sftp=ssh.open_sftp()
推荐答案
看起来像是误会。您的代码不执行任何端口转发。
有关正确的代码,请参阅Nested SSH using Python Paramiko。
如果您需要SFTP,而不是外壳,只需执行以下操作:
jhost.open_sftp()
而不是
jhost.exec_command(command)
强制性警告:请勿使用
AutoAddPolicy
-这样做会失去对MITM attacks的保护。有关正确的解决方案,请参阅Paramiko "Unknown Server"。
这篇关于使用Python Paramiko的端口转发和开放的SFTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:使用Python Paramiko的端口转发和开放的SFTP


基础教程推荐
猜你喜欢
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01