By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

Getting the bytes or percent uploaded/downloaded through FTP?

P: n/a
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.

Sep 5 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Na****@gmail.com wrote:
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')
--
Benji York

Sep 5 '05 #2

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

Sep 5 '05 #3

P: n/a
Na****@gmail.com wrote:
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....s/ftpmirror.py

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Sep 5 '05 #4

P: n/a
Steve Holden wrote:
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....s/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>

Sep 5 '05 #5

P: n/a
Thanks guys. I'll try to these things too work.

Sep 5 '05 #6

P: n/a
Thanks guys. I'll try to these things too work.

Sep 5 '05 #7

P: n/a
Wait, can this be used when uploading a file?

Sep 5 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.