我想使用scp在两个Ubuntu服务器之间传输文件,我在两个系统之间测试了scp并且它工作得很好.所以我不想每次都需要获取文件时执行命令所以我想写一个自动的python脚本使用scp从其他主机下载文件.
在网上搜索时,我发现这个Paramiko模块,我在安装时遇到了麻烦,我已经使用模块对其进行了纠正cryptography
.现在,下面的终端解释了真正的麻烦.
>>> from paramiko import SSHClient >>> from scp import SCPClient >>> ssh = SSHClient() >>> ssh>>> ssh.load_system_host_keys() >>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) >>> ssh.connect('somename@192.168.100.100') Traceback (most recent call last): File " ", line 1, in File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 296, in c onnect to_try = list(self._families_and_addresses(hostname, port)) File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 200, in _ families_and_addresses addrinfos = socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_S TREAM) socket.gaierror: [Errno -2] Name or service not known >>> ssh.connect('192.168.100.100') Traceback (most recent call last): File " ", line 1, in File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 361, in c onnect server_key) File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 672, in m issing_host_key raise SSHException('Server %r not found in known_hosts' % hostname) paramiko.ssh_exception.SSHException: Server '192.168.100.100' not found in known_hos ts
我已经更改了ip和用户名以便安全使用,somename is replaced
但我已经尝试过original username
.所以我尝试了几次,但我仍然得到同样的错误.
有关此问题的任何建议吗?请帮助.
也许你错过了missing_host_key_policy
这个如何:
proxy = None client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(host['hostname'], username=host['user'], sock=proxy)
更多例子:www.programcreek.com