On Fri, 2005-09-16 at 19:27 -0700, Nainto wrote:
> Hello, I have posted before about trying to find the status of an FTP
> uplaod but couldn't get anything to work. After some more searching I
> found
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/76be9a994547db4/91917c906cdc04d4?q=ftp+progress&rnum=1#91917c906cdc04d4
> but it does not seem to work because it just uploads the file and does
> not print a . onto the screen. HEre is the code I have when I'm using
> the code from that link.
> import ftplib
> import os
> class dot_FTP(ftplib.FTP):
>       def storbinary(self, cmd, fp, blocksize=8192):
>               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()
> 
> 
> ftp = ftplib.FTP("FTPADDRESS")
> ftp.login("user","pass")
> file = "/file"
> ftp.storbinary("STOR " + file, open(file, "rb"), 1024)
> ftp.quit()
> Does anyone know why this is not working? IS there any other way to
> find out when a chunc has been sent or the bytes uploaded of a file?
> Thanks.
> 

... and I haven't tried this myself, but you should be able to subclass
the builtin file object and prepare your own read() method.  Something
like

class ProgressFile(file):

    def read(self, size = None):
        print '.',

        if size is not None:
            return file.read(self, size)
        else:
            return file.read()

May need some tweaking.. then store the file as

ftp.storbinary("STOR " + file, ProgressFile(file, "rb"), 1024)

Give it a try..

-m

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to