Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ftp callback
#1
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
Reply
#2
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()
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020