我已经在本地机器上使用 proftpd 设置了 SFTP 服务器。它工作正常,除了上传大于大约 30000 个字符的文件时它会超时。
通过 proftpd 从命令行上传没有任何问题,使用 paramiko 上传到不同的 SFTP 服务器也可以。这让我认为 paramiko 和 proftpd 之间的交互存在一个错误。
我制作了一个小脚本来说明问题:
import paramiko
transport = paramiko.Transport(('localhost', 2220)) # my proftpd SFTP port
transport.connect(username='x', password='x')
client = paramiko.SFTPClient.from_transport(transport)
with open('testimage.jpg') as f: # 35241 characters
content = f.read()
with client.open('testimage.jpg', 'w') as f:
f.write(content)
我的 SFTP 特定 proftpd 配置:
<IfModule mod_sftp.c>
<VirtualHost 0.0.0.0>
Include /etc/proftpd/conf.d
SFTPEngine on
SFTPLog /var/log/proftpd/sftp.log
Port 2220
SFTPHostKey /etc/ssh/ssh_host_rsa_key
SFTPHostKey /etc/ssh/ssh_host_dsa_key
SFTPAuthMethods password
SFTPCompression delayed
MaxLoginAttempts 3
</VirtualHost>
</IfModule>
10分钟后,程序退出并吐出这个错误:
Traceback (most recent call last):
File "ftptest.py", line 9, in <module>
f.write(content)
File "/Library/Python/2.7/site-packages/paramiko/file.py", line 330, in write
self._write_all(data)
File "/Library/Python/2.7/site-packages/paramiko/file.py", line 447, in _write_all
count = self._write(data)
File "/Library/Python/2.7/site-packages/paramiko/sftp_file.py", line 176, in _write
self._reqs.append(self.sftp._async_request(type(None), CMD_WRITE, self.handle, long(self._realpos), data[:chunk]))
File "/Library/Python/2.7/site-packages/paramiko/sftp_client.py", line 668, in _async_request
self._send_packet(t, msg)
File "/Library/Python/2.7/site-packages/paramiko/sftp.py", line 170, in _send_packet
self._write_all(out)
File "/Library/Python/2.7/site-packages/paramiko/sftp.py", line 135, in _write_all
raise EOFError()
EOFError
使用 paramiko 1.15 和 proftpd 1.3.5