Python FTP uploading bar
Question: I am uploading a file with FTPLib in python and have a cli loadingbar with
[progressbar 2.2.](http://pypi.python.org/pypi/progressbar/2.2) I need to make
a loading bar to tell the progress of the upload.

Does anyone have any info on the topic?

Thanks, giodamelio

* * *

As Senthil Kumaran pointed out, there is a callback parameter in the
ftplib.storbinary function but I do not know how to use it.

I tried this. I expected it to print the message every time a byte was
uploaded.

    
    
    import ftplib
    
    def callback():
        print("This is the callback function")
    
    s = ftplib.FTP('myserver.com','login','password') # Connect
    
    f = open('test.txt','rb')                # file to send
    s.storbinary('STOR test.txt', f, 1024, callback())         # Send the file
    
    f.close()                                # Close file and FTP
    s.quit()
    


Answer: Small change to your code:

    
    
    import ftplib
    
    def callback(p):
        print("This is the callback function")
    
    s = ftplib.FTP('myserver.com','login','password') # Connect
    
    f = open('test.txt','rb')                # file to send
    s.storbinary('STOR test.txt', f, 1024, callback)         # Send the file
    
    f.close()                                # Close file and FTP
    s.quit()
    

The callback needs to be called later on. If you invoke it as you pass it as a
parameter, it's return value is passed instead. Since your `callback` function
has no return, it would pass in `None`.

