I have taken a look at the code that dose one download at time, in
multi threaded manner: http://aspn.activestate.com/ASPN/Coo.../Recipe/465531
What I wanted to do is, make it download multiple files at the same
time. I am new to python and have gone over "Dive In To Python"
yesterday. Can some give a idea what I need to do. Once I understand
the big picture, then I can piece together. 12 6160
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.'
Justin Ezequiel wrote:
from TaskQueue import TaskQueue
what Python version is this ?
</F>
Justin Ezequiel wrote:
Fredrik Lundh wrote:
>Justin Ezequiel wrote:
from TaskQueue import TaskQueue
what Python version is this ?
</F>
oops. forgot to note...
http://aspn.activestate.com/ASPN/Coo.../Recipe/475160
Also noteworthy: "This recipe was accepted for inclusion in Py2.5.", i. e.
in Python 2.5 you can use Queue instead of TaskQueue.
Peter
Where or What folder does the ftp files get downloaded to?
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.'
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.'
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
It works using ftp.microsoft.com. But where does it put the downloaded
files? can I specify a download folder location?
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
It places the ftp downloaded contents on the same folder as the this
ftp python script. How do I set a diffrent download folder location?
johnny wrote:
It works using ftp.microsoft.com. But where does it put the downloaded
files? can I specify a download folder location?
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
johnny wrote:
It places the ftp downloaded contents on the same folder as the this
ftp python script. How do I set a diffrent download folder location?
by prepending a directory name to the filename in the open(p, 'wb') call.
</F>
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("te**@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
Ok I fixed it. Needed to put in username, and password in the c.login
inside while True loop.
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')
johnny wrote:
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("te**@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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dominik |
last post by:
I am writing application which must download multiple
files simultaneous. Initially I wanted to use multiple
threads to achieve this task but later I heard that Net
is "using" separate thread from...
|
by: James Radke |
last post by:
Hello,
I have a multithreaded windows NT service application (vb.net 2003) that I
am working on (my first one), which reads a message queue and creates
multiple threads to perform the processing...
|
by: Ryan Malone |
last post by:
I have a situation where I need to download multiple files in a vb.net
application.
To speed up the process, I am trying to download multiple files at one
time looping through each of the files...
|
by: VBTricks.de.vu Webmaster |
last post by:
Hello,
at the moment I'm not able to finish my program. That means, I have a
problem I can't solve myself. Therefore I'm asking those who already
worked with HttpWebRequest... and threads.
...
|
by: Scott |
last post by:
Front-end Access 2000
I have a stored procedure that has 2 parameters BusinessUnitID and
Year.
It returns multiple record sets (5 to be exact).
I thought I could use a Pass through query but...
|
by: santosh |
last post by:
Hi all,
In the following program I allocate a block of pointers to type char,
initialised to zero. I then point each of those pointers to a block of
allocated memory of fixed size (33 bytes). A...
|
by: gjzusenet |
last post by:
Hello.
Though Python supports threading, I think it is limited to python code
- as soon as you issue a command that uses an external (C?) module, all
of your python threads hang until this command...
|
by: keerthyragavendran |
last post by:
hi
i'm downloading a single file using multiple threads...
how can i specify a particular range of bytes alone from a single
large file... for example say if i need only bytes ranging from...
|
by: ShashiGowda |
last post by:
Hey there i made a script to download all images from a web site but
it runs damn slow though I have a lot of bandwidth waiting to be used
please tell me a way to use urllib to open many...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |