-
-
Save hivefans/c878dce16d10e182cb8b to your computer and use it in GitHub Desktop.
ftp下载显示现在进度|-|{"files":{"ftp_download.py":{"env":"plain"}},"tag":"bigdata"}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ftplib | |
| import sys | |
| from progressbar import ProgressBar | |
| from progressbar.widgets import Percentage, FileTransferSpeed, ETA, Bar | |
| if len(sys.argv) < 4: | |
| print("请输入ftp地址,用户,密码和文件".decode("utf8")) | |
| sys.exit(0) | |
| ftp = ftplib.FTP(sys.argv[1], sys.argv[2], sys.argv[3]) | |
| files = sys.argv[4].split(',') | |
| for f in files: | |
| filesize = ftp.size("/" + f) | |
| widgets = ['Download [' + f + ']: ', Percentage(), ' ', | |
| Bar(marker='*', left='[', right=']'), | |
| ' ', ETA(), ' ', FileTransferSpeed()] | |
| p = ProgressBar(maxval=filesize, widgets=widgets).start() | |
| with open(f, 'w') as f2: | |
| def callback(chunk): | |
| f2.write(chunk) | |
| p.update(p.currval + len(chunk)) | |
| ftp.retrbinary('RETR /' + f, callback) | |
| p.finish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment