Multiple FTP download using Muliti thread
johnny
rampeters at gmail.com
Mon Dec 4 19:08:44 EST 2006
When I run the following script, with host and password and username
changed, I get the following errors:
raise error_temp, resp
error_temp: 421 Unable to set up secure anonymous FTP
Dose the host should allow 4 simultaneous login at a time?
Justin Ezequiel wrote:
> import ftplib, posixpath, threading
> from TaskQueue import TaskQueue
>
> def worker(tq):
> while True:
> host, e = tq.get()
>
> c = ftplib.FTP(host)
> c.connect()
> try:
> c.login()
> p = posixpath.basename(e)
> fp = open(p, 'wb')
> try: c.retrbinary('RETR %s' % e, fp.write)
> finally: fp.close()
> finally: c.close()
>
> tq.task_done()
>
> if __name__ == '__main__':
> q = TaskQueue()
> host = 'ftp.microsoft.com'
>
> c = ftplib.FTP(host)
> c.connect()
> try:
> c.login()
> folder = '/deskapps/kids/'
> for n in c.nlst(folder):
> if n.lower().endswith('.exe'):
> q.put((host, n))
> finally: c.close()
>
> numworkers = 4
> for i in range(numworkers):
> t = threading.Thread(target=worker, args=(q,))
> t.setDaemon(True)
> t.start()
>
> q.join()
> print 'Done.'
More information about the Python-list
mailing list