【发布时间】:2011-08-06 02:26:15
【问题描述】:
我在 python 中使用 FTPLib 上传一个文件,并有一个带有 progressbar 2.2. 的 cli 加载栏 我需要制作一个加载栏来告诉上传进度。
有人知道这个话题的任何信息吗?
谢谢,乔达梅里奥
正如 Senthil Kumaran 指出的,ftplib.storbinary 函数中有一个回调参数,但我不知道如何使用它。
我试过这个。我希望它在每次上传一个字节时打印消息。
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()
【问题讨论】:
-
不要调用你的回调 - 你实际上是在这里传递 None 作为回调。
-
我以前从未使用过回调函数,所以我有点困惑。我应该改变哪一部分?
标签: python file-upload ftp