Progress indicator during FTP upload
Christophe Delord
no.spam
Sun Jan 4 16:10:12 EST 2004
On Sun, 04 Jan 2004 19:31:34 +0100, Frantisek Fuka wrote:
> My application uses ftplib to upload files to remote server. What is
> the cleanest way to provide progress indicator for long files? What
> exactly should I override in the ftplib (I am not very proficient in
> the FTP protocol)?
>
Hello,
To update my web site I wrote a script in wich I have overriden
ftplib.FTP to print a dot when a block of bytes is sent. Here is my
dot_FTP class :
class dot_FTP(ftplib.FTP):
def storbinary(self, cmd, fp, blocksize=8192):
''' Store a file in binary mode.'''
self.voidcmd('TYPE I')
conn = self.transfercmd(cmd)
while 1:
buf = fp.read(blocksize)
if not buf: break
conn.send(buf)
sys.stdout.write('.')
sys.stdout.flush()
conn.close()
return self.voidresp()
I just took the code of storbinary in ftplib.py and added the wanted
output.
Christophe.
More information about the Python-list
mailing list