ftp callback - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: ftp callback (/thread-12803.html) |
ftp callback - roberto - Sep-13-2018 Hello, I want to use a callback when upload of a file to ftp . Here is my code: from ftplib import FTP def UploadTracker(): print "HELLO" myftp = FTP() myftp.connect(host='mysite.com') myftp.login('me','mypw') myftp.storbinary('STOR mydata.txt', open('mydata.txt', 'rb'), callback=UploadTracker()) myftp.quit() Upload of mydata.txt works ok , but the result shows only one "HELLO" at start of upload ... mydata.txt weigth is 1800ko . So I was waiting for many many HELLO message , each time a block of 8192 bytes is uploaded , but it does'nt works. Did I make a error ? I have tried different ways of writing this code (with global variables to follow upload, etc ...) but no differences, only one callback to UploadTracker is made . What is my error ? Many thanks for your help . Roberto RE: ftp callback - heiner55 - Jun-07-2019 Remove "()" after callback: myftp.storbinary(..., callback=UploadTracker) from ftplib import FTP def UploadTracker(): print("HELLO") myftp = FTP() myftp.connect(host='mysite.com') myftp.login('me','mypw') myftp.storbinary('STOR mydata.txt', open('mydata.txt', 'rb'), callback=UploadTracker) myftp.quit() |