我到处找,找不到解决这个问题的方法,ftplib storbinary 回调。这是我第一次使用回调,所以它可能很愚蠢,我假设每次上传 8192 字节时我都有一些代码应该调用我的函数(这就是我认为回调在研究后的工作方式)。
#In main thread
def ftpcallback(intid):
ftpuploaded = transStatus[intid][3] + 8192 #transStatus[intid] equals 0 to start with
if ftpuploaded > transStatus[intid][2]: ftpuploaded = transStatus[intid][2] #Is this needed? It's supposed to just keep the value below the file size
transStatus[intid][3] = ftpuploaded
print (transStatus[intid][3]) #Always outputs 8192
print("Callback called")
#Not in main thread
#FTP and file open code
self.ftp.storbinary("STOR " + self.destname, self.f, 1, ftpcallback(self.intid)) #1 to (hopefully) spam the output more
#close FTP and file code
无论何时运行,回调只运行一次,即使是 10MB 的文件。我究竟做错了什么?提前致谢