FtpUtils Progress Bar
Justin Ezequiel
justin.mailinglists at gmail.com
Thu Sep 14 00:48:27 EDT 2006
iwcook58 at gmail.com wrote:
>
> Does anyone have an example on how to show the progress of the
> upload/download when using ftputil?
>
haven't used ftputil in quite a while ...
but using ftplib...
import ftplib
class Callback(object):
def __init__(self, totalsize, fp):
self.totalsize = totalsize
self.fp = fp
self.received = 0
def __call__(self, data):
self.fp.write(data)
self.received += len(data)
print '\r%.3f%%' % (100.0*self.received/self.totalsize),
if __name__ == '__main__':
host = 'ftp.microsoft.com'
src = '/deskapps/games/public/Hellbender/heltrial.exe'
c = ftplib.FTP(host)
c.login()
size = c.size(src)
dest = 'heltrial.exe'
f = open(dest, 'wb')
w = Callback(size, f)
c.set_pasv(0)
c.retrbinary('RETR %s' % src, w, 32768)
f.close()
c.quit()
More information about the Python-list
mailing list