📜  ftplib 进度 - 任何代码示例

📅  最后修改于: 2022-03-11 14:56:06.843000             🧑  作者: Mango

代码示例1
from ftplib import FTP
import os.path

# Init
sizeWritten = 0
totalSize = os.path.getsize('test.zip')
print('Total file size : ' + str(round(totalSize / 1024 / 1024 ,1)) + ' Mb')

# Define a handle to print the percentage uploaded
def handle(block):
    sizeWritten += 1024 # this line fail because sizeWritten is not initialized.
    percentComplete = sizeWritten / totalSize
    print(str(percentComplete) + " percent complete")

# Open FTP connection
ftp = FTP('website.com')
ftp.login('user','password')

# Open the file and upload it
file = open('test.zip', 'rb')
ftp.storbinary('STOR test.zip', file, 1024, handle)

# Close the connection and the file
ftp.quit()
file.close()