Skip to content

Instantly share code, notes, and snippets.

@turbidsoul
Created June 23, 2013 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save turbidsoul/5844112 to your computer and use it in GitHub Desktop.
Save turbidsoul/5844112 to your computer and use it in GitHub Desktop.
ftp下载显示现在进度
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