通过paramiko将大文件上传到proftpd超时

时间:2014-09-22 16:45:16

标签: python sftp paramiko eoferror proftpd

我在本地计算机上使用proftpd设置了SFTP服务器。它工作正常,但上传大于大约30000个字符的文件时会超时。

从命令行上传到proftpd工作没有任何问题,使用paramiko上传到不同的SFTP服务器也可以。这让我觉得paramiko和proftpd之间的交互中特别存在一个bug。

我制作了一个小脚本来说明问题:

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

1 个答案:

答案 0 :(得分:0)

对于paramiko,4 GB的默认窗口大小太大,导致数据传输停止。

通过将此问题添加到proftpd SFTP配置中解决了该问题:
SFTPClientMatch ".*" channelWindowSize 3999MB