我正在尝试从 SFTP 服务器下载一些文件。我使用这个代码:
keydata = b"""AAAAB3Nza.............CNpvoUP7p"""
key = paramiko.RSAKey(data=decodebytes(keydata))
cnopts = pysftp.CnOpts()
cnopts.hostkeys.add(host, 'ssh-rsa', key)
host = 'sftp.foo.com'
username = 'test'
password = 'test'
with pysftp.Connection(host=host, username=username, password=password, cnopts=cnopts) as sftp:
sftp.listdir()
.....
但我收到以下错误:
Exception raised:
Traceback (most recent call last):
File "/home/myuser/src/ftp-data/ftp_data/downloader_v2.py", line 25, in main
sftp.listdir()
File "/home/myuser/environments/python3.5.2_ubuntu16.04/lib/python3.5/site-packages/pysftp/__init__.py", line 591, in listdir
self._sftp_connect()
File "/home/myuser/environments/python3.5.2_ubuntu16.04/lib/python3.5/site-packages/pysftp/__init__.py", line 205, in _sftp_connect
self._sftp = paramiko.SFTPClient.from_transport(self._transport)
File "/home/myuser/environments/python3.5.2_ubuntu16.04/lib/python3.5/site-packages/paramiko/sftp_client.py", line 165, in from_transport
window_size=window_size, max_packet_size=max_packet_size
File "/home/myuser/environments/python3.5.2_ubuntu16.04/lib/python3.5/site-packages/paramiko/transport.py", line 879, in open_session
timeout=timeout,
File "/home/myuser/environments/python3.5.2_ubuntu16.04/lib/python3.5/site-packages/paramiko/transport.py", line 1006, in open_channel
raise e
File "/home/myuser/environments/python3.5.2_ubuntu16.04/lib/python3.5/site-packages/paramiko/transport.py", line 2055, in run
ptype, m = self.packetizer.read_message()
File "/home/myuser/environments/python3.5.2_ubuntu16.04/lib/python3.5/site-packages/paramiko/packet.py", line 459, in read_message
header = self.read_all(self.__block_size_in, check_rekey=True)
raise EOFError()
EOFError
相同的代码可以在我尝试过的其他 SFTP 主机上正常运行。我还可以使用命令行(Ubuntu)正确下载文件sftp。
listdir()
如果我替换为pwd()
or cd()
.... ,我会得到同样的错误。
我使用以下版本:paramiko==2.7.2 和 pysftp==0.2.9
我在这里缺少什么?
芜湖不芜
相关分类