FTP without timeout?

Steve Holden steve at holdenweb.com
Tue Oct 5 00:33:39 CEST 2004


Chris wrote:

> How do I setup an FTP connection without timeout using ftplib.FTP?
> 
> I've tried
> ftp = ftplib.FTP('server')
> ftp.login('user', 'xxx')
> ftp.sock.settimeout(None)
> or
> ftp.sock.settimeout(3600)
> or
> ftp.sock.setblocking(True)
> but it always timeout after 10 minutes of inactivity.
> The server allows idle up to 240 minutes before disconnecting.
> 
> Please help! Thanks in advance.
> 
> Chris
> 
> 
Try putting

import socket
socket.setdefaulttimeout(240*60)

at the start of your code to see whether this makes a difference. This 
ensures that the socket timeout is established before a connection is 
made to the remote endpoint.

Though frankly, from the documentation, since there doesn't appear to be 
a default timeont on sockets, I'm not sure where this bizarre ten minute 
timeout is coming from. The string "time" doesn't appear at all in the 
ftplib source, so I'm somewhat stumped.

Are you sure the server doesn't require some sort of keepalive from the 
client?

regards
  Steve
-- 
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119



More information about the Python-list mailing list