Problem in dealing with timeout and ftplib? (py2.3a2)

Steve Holden sholden at
Tue Feb 25 19:19:46 CET 2003

"Chen" <chenpuqing at> wrote in message
news:b3g73d$1ps6$1 at
> Hi, everyone!
> I'm writting an ftp resource scanner. The program starts many threads and
> each one searchs in an IP range. If a host cannot be connected in a
> specified time, say, 10 seconds, then the thread should go to the next
> I've implemented the  function with python-2.2.2 and Timothy O'Malley's
> (many thanks to him :-) . The program works very well.
> now, since python-2.3 provides such a builtin function in, I
> to change to it.
> But, I find the `sock' attribute of ftplib.FTP object is `None' before the
> connection is established. So I can't use the `.sock.settimeout' method
> before I use `.connect' method of FTP object.
> By a little tracing, I found the `sock' attribute is created in the
> `connect' method of the FTP object. So I can't use the timeout function in
> connection.
> I think I must change the file But, are there any other
> solutions?

Well, truthfully it was probably never a very good idea to go poking around
in the implementation details of the FTP object. The recommended way to get
the right timeout using O'Malley's module was to use its
"setdefaulttimeout()" function to establish a default timeout far any
sockets created without knowledge of the library.

Isn't there an equivalent to this in the new socket module?

Steve Holden                        
Python Web Programming       
Register for PyCon now!  

More information about the Python-list mailing list