所以我正在编写一个脚本,用于递归搜索文件夹中的 .mkv 文件并将其上传到我的 NAS。我已经让脚本运行但是我看不到进度。我导入了这个在 github 上找到的 progressbar,并且能够使用演示看到它工作。这就是我想要的,然而他们包含的 FTP 示例是从服务器检索文件,而我需要上传。
如何获取上传量并在间隔上运行更新以更新进度条?
下面是我已经为上传准备好的代码:
import os
import ftplib
import ntpath
ntpath.basename("a/b/c")
def path_leaf(path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
from glob import glob
FileTransferList = [y for x in os.walk('/tmp/rippedMovies') for y in glob(os.path.join(x[0], '*.mkv'))]
global ftp
def FTP_GLOB_transfer(URL, UserName, Password):
ftp = ftplib.FTP(URL, UserName, Password) # connect to host, default port
print URL, UserName, Password
for file in FileTransferList:
FileName = path_leaf(file)
print file
TheFile = open(file, 'r')
ftp.storbinary('STOR ' + FileName, TheFile, 1024)
TheFile.close()
ftp.quit()
ftp = None
FTP_GLOB_transfer('<IP>', '<USER>', '<PASSWORD>')