我正在尝试制作一个通过ssh下载(或上传)文件的脚本,因为已从防火墙禁用了ftp端口。这是我的脚本:
import os
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.170.21.93', username="abhishek", password="@bhishek$")
sftp = ssh.open_sftp()
localpath = 'abc.txt'
remotepath = '/opt/crestelsetup/patchzip'
sftp.put(localpath, remotepath)
sftp.close()
ssh.close()
这给了我“ IOError:失败”,任何人都可以帮忙吗?
您需要明确指定远程路径:
import os
import paramiko
ssh = paramiko.SSHClient()
ssh.connect('10.170.21.93', username="abhishek", password="@bhishek$")
sftp = ssh.open_sftp()
localpath = 'abc.txt'
remotepath = '/opt/crestelsetup/patchzip/abc.txt'
sftp.put(localpath, remotepath)
sftp.close()
ssh.close()
根据Martin Prikryl的评论,强烈建议不要使用以下代码行,因为它会使您在中间攻击中与人为敌,但是,这可能是丢失主机密钥的临时解决方案
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句