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

Chen chenpuqing at 163.net
Tue Feb 25 17:49:20 CET 2003


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 host.

I've implemented the  function with python-2.2.2 and Timothy O'Malley's
timeoutsocket.py (many thanks to him :-) . The program works very well. But
now, since python-2.3 provides such a builtin function in socket.py, I want
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 ftplib.py. But, are there any other
solutions?







More information about the Python-list mailing list