3

Using Python 2.6 and downloading files from an FTP server in passive mode, I found that retrbinary fails with a timeout if the source file is empty (0 bytes). Is this a bug or am I missing a configuration option?

ftp.retrbinary('RETR digital.conf', open('digital.conf','wb').write)

Downloading digital.conf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "download.py", line 13, in run
    ftp.retrbinary('RETR %s' % source, callback)
  File "c:\Python26\lib\ftplib.py", line 398, in retrbinary
    conn = self.transfercmd(cmd, rest)
  File "c:\Python26\lib\ftplib.py", line 360, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "c:\Python26\lib\ftplib.py", line 337, in ntransfercmd
    resp = self.getresp()
  File "c:\Python26\lib\ftplib.py", line 216, in getresp
    raise error_temp, resp
ftplib.error_temp: 421 Timeout

Other non-zero byte files transfer fine.

Bruce Alport
  • 432
  • 5
  • 12

1 Answers1

0

This is Your session idle time too long.You can file after the President into instantiate ftplib. Otherwise. Modify ftp software configuration.

For example, you use vsftpd, you can add the following configuration to vsftpd.conf:

idle_session_timeout=60000 # The default is 600 seconds

dongweiming
  • 811
  • 1
  • 8
  • 8