Multi-threaded FTP Question

dbandler at gmail.com dbandler at gmail.com
Tue Jul 11 16:09:37 EDT 2006


There are n instances of ftplib.FTP.

Funny thing is that I tried to run the code twice, concurrently, in two
separate IDLE instances. Each instance had four threads/ftp calls.
Again, only five ftp connections were allowed on my computer.  The code
errored out on the sixth attempt.

I wonder if there' s some underlying software being called that has a
limit on the number of ftp connections allowed at any point in time.
I'm tempted to try this on cygwin to see if the behavior is different.

Derek

import ftplib, zipfile, datetime, os
from threading import Thread, Lock


class ftpDownload(Thread):
    def __init__(self, year, quarter):
        Thread.__init__(self)
        self.quarter     = str(quarter)
        self.year         = str(year)
        self.filename   = ""
        self.ftp = ftplib.FTP('xxxxxxx')
        self.ftp.login()
        self.lock         = Lock()

    def run(self):
        filehandle = open(self.filename,'wb')
        self.ftp.retrbinary('RETR /xxxxx/xxxxxxx/' + self.year + '/QTR'
+ self.quarter + '/xxxxxxx.zip', filehandle.write)
        filehandle.close()
        self.ftp.close()

ftplist = []
for year in range(1990,2000):
    for quarter in range(1,5):
        current = ftpDownload(year, quarter)
        ftplist.append(current)
        current.start()

for job in ftplist:
    job.join()




Jeremy Jones wrote:
> dbandler at gmail.com wrote:
> > I'm trying to use ftp in python in a multi-threaded way on a windows
> > box - python version 2.4.3.  Problem is that it appears that it's only
> > possible to have five instances/threads at one point in time.  Errors
> > look like:
> >
> >    File "C:\Python24\lib\ftplib.py", line 107, in __init__
> >     self.connect(host)
> >   File "C:\Python24\lib\ftplib.py", line 132, in connect
> >     self.welcome = self.getresp()
> >   File "C:\Python24\lib\ftplib.py", line 208, in getresp
> >     resp = self.getmultiline()
> >   File "C:\Python24\lib\ftplib.py", line 194, in getmultiline
> >     line = self.getline()
> >   File "C:\Python24\lib\ftplib.py", line 184, in getline
> >     if not line: raise EOFError
> > EOFError
> >
> > Is it possible to have more than five simultaneous ftp connections?
> >
> > Thanks.
> >
> > Derek
>
> I replied to this about 4 hours ago from my gmail email account (not my
> google groups account associated with the same email addres), but
> haven't seen it show up, so I apologize if this is a dupe.
>
> Would you mind posting your code?  Are you trying to pass the same FTP
> connection object to all 5 threads?
> 
> - Jeremy M. Jones




More information about the Python-list mailing list