faqts : Computers : Programming : Languages : Python : Common Problems : FTP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 5 people (100%) answered Yes
Recently 3 of 3 people (100%) answered Yes

Entry

I'm currently using the storbinary method for transferring files, how can I get some indication that I've transferred xx% of the file, or 100,000 bytes so far?

Jun 5th, 2000 06:34
unknown unknown, Peter Schneider-Kamp


Just define your own version of storbinary in your module:

def mystorbinary(self, cmd, fp, blocksize):
  '''Store a file in binary mode and print stuff.'''
  self.voidcmd('TYPE I')
  conn = self.transfercmd(cmd)
  counter = 0
  while 1:
    print counter,"Bytes read yet."
    buf = fp.read(blocksize)
    if not buf: break
    conn.send(buf)
    counter = counter + blocksize
  conn.close()
  return self.voidresp()