我是python的新手,我第一次通过python脚本尝试sftp。我希望我的python脚本从双栈机器(IPv4和IPv6都存在)获取文件。以下是我用于Paramiko的代码片段:
host = ip #ip is a string that has the value of IP
port = 22
transport = paramiko.Transport((host, port))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport
当我使用IPv4代码时,它工作正常。但是当我用ip地址替换ip时,会抛出以下错误:
Traceback (most recent call last):
File "MyFile.py", line 92, in <module>
putFile()
File "MyFile.py", line 29, in analyzeLogs
transport = paramiko.Transport((host, port))
File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 289, in __init__
sock.connect((hostname, port))
File "<string>", line 1, in connect
socket.gaierror: [Errno -2] Name or service not known
我检查了一个解决方案,发现有人建议添加接口和IP,但在尝试相同的时候我收到了以下错误:
Traceback (most recent call last):
File "MyFile.py", line 92, in <module>
putFile()
File "MyFile.py", line 29, in analyzeLogs
transport = paramiko.Transport((host, port))
File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 289, in __init__
sock.connect((hostname, port))
File "<string>", line 1, in connect
socket.gaierror: [Errno -9] Address family for hostname not supported
我的原始服务器不是双栈机器,因此我只需要通过IPv6传输文件。
注意:当我在linux中使用sftp命令时,它适用于ipv4和ipv6
非常感谢任何可能的解决方案或其他建议
答案 0 :(得分:1)
Paramiko的CLLocationManager
类支持传入套接字对象和元组。那么也许尝试专门传入ipv6套接字?
Transport