Multiple FTP download using Muliti thread
johnny
rampeters at gmail.com
Tue Dec 5 13:21:58 EST 2006
I am getting the following error:
raise error_temp, resp
error_temp: 421 Unable to set up secure anonymous FTP
Here is the code:
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('H:/eclipse/workspace/src/ftp_download/' + 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'
host = 'mysite.com'
c = ftplib.FTP(host)
c.connect()
try:
#c.login()
c.login("temp at mysite.com","temppass" )
#folder = '/deskapps/kids/'
folder = ''
for n in c.nlst(folder):
#if n.lower().endswith('.exe'):
# q.put((host, n))
if n.lower().endswith('.jpg'):
q.put((host, n))
elif n.lower().endswith('.jpeg'):
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.'
Justin Ezequiel wrote:
> johnny wrote:
> > 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?
> >
>
> does it work using ftp.microsoft.com?
>
> post your code
More information about the Python-list
mailing list