Getting the bytes or percent uploaded/downloaded through FTP?

Discussion in 'Python' started by Nainto, Sep 5, 2005.

  1. Nainto

    Nainto Guest

    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.
    Nainto, Sep 5, 2005
    1. Advertisements

  2. Nainto

    Benji York Guest

    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('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))

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

    import urllib
    urllib.urlretrieve(url, destination, reporter)
    Benji York, Sep 5, 2005
    1. Advertisements

  3. Nainto

    Nainto Guest

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

    Steve Holden Guest

    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

    Steve Holden, Sep 5, 2005
  5. to handle arbitrary servers, you also need a flexibel LIST response
    parser; see:

    python bindings:


    Fredrik Lundh, Sep 5, 2005
  6. Nainto

    Nainto Guest

    Thanks guys. I'll try to these things too work.
    Nainto, Sep 5, 2005
  7. Nainto

    Nainto Guest

    Thanks guys. I'll try to these things too work.
    Nainto, Sep 5, 2005
  8. Nainto

    Nainto Guest

    Wait, can this be used when uploading a file?
    Nainto, Sep 5, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.