Getting the bytes or percent uploaded/downloaded through FTP?

N

Nainto

Hi, I'm just wondering if there is any way to get the number of bytes,
or the percentage, that have been uploaded/downloaded when
uploading/downloading a file throught ftp in Python. I have searched
Google many times but could find nothing.
 
B

Benji York

Hi, I'm just wondering if there is any way to get the number of bytes,
or the percentage, that have been uploaded/downloaded when
uploading/downloading a file throught ftp in Python. I have searched
Google many times but could find nothing.

If you're using urllib you can do something like this:

def reporter(block, block_size, total_size):
left = total_size - block * block_size
sys.stderr.write('\r')
sys.stderr.write('Downloading %s: ' % file_name)
if left > 0: # the estimate is a bit rough, so we fake it a little
sys.stderr.write('%sK left.' % (left/1024))
else:
sys.stderr.write('done.')

# it's possible that this line is shorter than the previous,
# so we need to "erase" any leftovers
sys.stderr.write(' '*10)
sys.stderr.write('\b'*10)

import urllib
urllib.urlretrieve(url, destination, reporter)
sys.stderr.write('\n')
 
N

Nainto

Thanks, Benji but I need to be able to get the bytes and/or percent of
a download too. :-(
 
S

Steve Holden

Thanks, Benji but I need to be able to get the bytes and/or percent of
a download too. :-(
The only way I can think of to get the size of the file you're about to
download is using the FTP object's .dir() method. If you have the Tools
directory (standard on Windows, with source on other platforms) you can
take a look at the ftpmirror script - a fairly recent version can be seen at

http://weblog.cs.uiowa.edu/python-2.3.1/Tools/scripts/ftpmirror.py

regards
Steve
 
F

Fredrik Lundh

Steve said:
The only way I can think of to get the size of the file you're about to
download is using the FTP object's .dir() method. If you have the Tools
directory (standard on Windows, with source on other platforms) you can
take a look at the ftpmirror script - a fairly recent version can be seen at

http://weblog.cs.uiowa.edu/python-2.3.1/Tools/scripts/ftpmirror.py

to handle arbitrary servers, you also need a flexibel LIST response
parser; see:

http://cr.yp.to/ftpparse.html

python bindings:

http://c0re.23.nu/c0de/ftpparsemodule/

and

http://effbot.org/downloads/#ftpparse

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top