【发布时间】:2014-02-04 12:58:54
【问题描述】:
我需要使用 ftp.retrbinary 命令在 FTP 期间确定客户端 PC 的下载或上传速度。如何确定每个块下载的速度(以 Mbps 为单位)?
def download_file(block):
global sizeWritten
start_time = time.mktime(time.localtime())
file.write(block)
end_time = time.mktime(time.localtime())
os.system('CLS')
sizeWritten += len(block)
percentComplete = sizeWritten / totalSize
percentComplete = round((percentComplete*100),1)
# if totalTime != 0:
# throughput=sizeWritten/totalTime
# throughput=throughput/(1024*1024)
# throughput=throughput*8
# throughput=round(throughput,3)
# print(throughput, "MBPS")
print (percentComplete, "% complete")
try:
file = open('100file.zip', "wb")
print("File opened")
ftp.retrbinary("RETR " + '100file.zip' ,download_file)
print("Download Successful!")
except:
print("Error")
【问题讨论】:
标签: python upload download client