I want to transfer files between two Ubuntu Servers using scp, i have tested scp between the two systems and it worked perfectly fine.So i dont want to execute the command everytime i need to get files so i want to write a python script which automatically downloads files from other host using scp.
我想使用scp在两个Ubuntu服务器之间传输文件,我在两个系统之间测试了scp并且它工作得很好。所以我不想每次都需要获取文件时执行命令所以我想写一个自动的python脚本使用scp从其他主机下载文件。
While searching online i found this Paramiko module and i have trouble installing this and i have rectified this using module cryptography
.Now the real trouble is explained with the terminal below.
在网上搜索时,我发现了这个Paramiko模块,我在安装这个模块时遇到了麻烦,我已经使用模块加密技术纠正了这个问题。现在用下面的终端解释了真正的麻烦。
>>> from paramiko import SSHClient
>>> from scp import SCPClient
>>> ssh = SSHClient()
>>> ssh
<paramiko.client.SSHClient object at 0x1a41c90>
>>> 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 "<stdin>", line 1, in <module>
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 "<stdin>", line 1, in <module>
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
I have changed the ip and username for safe use somename is replaced
but i have tried with original username
.So i tried this several times but i still getting the same error.
我已经更改了ip和用户名以便安全使用somename被替换,但我尝试使用原始用户名。所以我尝试了几次,但我仍然得到相同的错误。
Any suggestions on this problem?Please Help.
有关此问题的任何建议吗?请帮助。
3 个解决方案
#1
12
Maybe you are missing the missing_host_key_policy
也许你错过了missing_host_key_policy
What about this one:
这个如何:
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)
more examples here: www.programcreek.com
更多例子:www.programcreek.com
#2
1
Try using this:
试试这个:
ssh.connect('host', username='username',password='password')
ssh.connect('host',username ='username',password ='password')
You can also add your public key to known hosts in server, if you wish to skip password and connect without giving your password. In that case use:
如果您希望跳过密码并在不提供密码的情况下进行连接,也可以将公钥添加到服务器中的已知主机。在这种情况下使用:
ssh.connect('host', username='username')
ssh.connect('host',username ='username')
#3
0
For me the solution was:
对我来说,解决方案是:
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(host, username=user,password=password)
#1
12
Maybe you are missing the missing_host_key_policy
也许你错过了missing_host_key_policy
What about this one:
这个如何:
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)
more examples here: www.programcreek.com
更多例子:www.programcreek.com
#2
1
Try using this:
试试这个:
ssh.connect('host', username='username',password='password')
ssh.connect('host',username ='username',password ='password')
You can also add your public key to known hosts in server, if you wish to skip password and connect without giving your password. In that case use:
如果您希望跳过密码并在不提供密码的情况下进行连接,也可以将公钥添加到服务器中的已知主机。在这种情况下使用:
ssh.connect('host', username='username')
ssh.connect('host',username ='username')
#3
0
For me the solution was:
对我来说,解决方案是:
client = SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(host, username=user,password=password)