我是python中的新手并尝试不同的东西。
目前正尝试将文本文件to_copy.txt
从具有本地IP 192.168.1.101
的远程计算机复制到我当前的计算机。
我从谷歌上搜索的内容似乎不起作用。
import paramiko
from scp import SCPClient
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("testme@192.168.1.101", password="look420")
print("Connected")
scp = SCPClient(ssh.get_transport())
scp.get("/home/testme/target_folder/to_copy.txt")
scp.close()
但是,当我运行这个时,我得到了错误;
Traceback (most recent call last):
File "/home/uc/Python_Projects/MoveFileAndFolder/move_remote.py", line 7, in <module>
ssh.connect("testme@192.168.1.101", password="look420")
File "/usr/local/lib/python3.4/dist-packages/paramiko/client.py", line 296, in connect
to_try = list(self._families_and_addresses(hostname, port))
File "/usr/local/lib/python3.4/dist-packages/paramiko/client.py", line 200, in _families_and_addresses
addrinfos = socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM)
File "/usr/lib/python3.4/socket.py", line 530, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
我在这里做错了什么?
注意:当前计算机正在运行Debian Jessie
,远程计算机正在运行Ubuntu 14.04.4 LTS
答案 0 :(得分:1)
scp(22)的端口可能未在远程计算机上打开。请检查命令行调用以确认您确实可以建立ssh或scp连接。
请点击此处了解更多详情
答案 1 :(得分:1)