久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Python 中顯示 FTP 下載進度(ProgressBar)

Show FTP download progress in Python (ProgressBar)(在 Python 中顯示 FTP 下載進度(ProgressBar))
本文介紹了在 Python 中顯示 FTP 下載進度(ProgressBar)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用以下 Python 腳本通過 FTP 下載文件.我想要的是在下載時查看進度的詳細信息.為此,我使用了 ProgressBar 但它沒有顯示任何內容.

I am downloading files over FTP using the following Python script. What I wanted is to see the details of the progress while downloading. For that I used ProgressBar but it isn't showing anything.

這是我的代碼:

import re
import os
import ftplib
import ntpath

import sys
import time

from progressbar import AnimatedMarker, Bar, BouncingBar, Counter, ETA, 
    AdaptiveETA, FileTransferSpeed, FormatLabel, Percentage, 
    ProgressBar, ReverseBar, RotatingMarker, 
    SimpleProgress, Timer, UnknownLength

ftp = ftplib.FTP("Your IP address")
ftp.login("Username", "password")
files = []

try:
    ftp.cwd("/feed_1")
    files = ftp.nlst()
    for fname in files:
        res = re.findall("2018-07-25", fname)
        if res:
            print 'Opening local file ' + ntpath.basename(fname)
            file = open(ntpath.basename(fname), 'wb')
            print 'Getting ' + ntpath.basename(fname)

            try:
                 widgets = ['Downloading: ', Percentage(), ' ',
                    Bar(marker='#',left='[',right=']'),
                    ' ', ETA(), ' ', FileTransferSpeed()]

                 pbar = ProgressBar(widgets=widgets, maxval=500)
                 pbar.start()
                 ftp.retrbinary('RETR ' + ntpath.basename(fname), file.write)

            except:
                pass

            print 'Closing file ' + ntpath.basename(fname)
            file.close() 
            print (fname)
            time.sleep(0.2)
            pbar.update()
            pbar.finish() 

        if not res:
            continue

except ftplib.error_perm , resp:
    if str(resp) == "550 No files found":
        print "No files in this directory"
        pass
    else:
        raise

請幫助了解這里的實際問題.謝謝:)

Please help in understanding what's actually wrong here. Thanks :)

推薦答案

你永遠不會更新 ProgressBar.您需要做的是:

You never update the ProgressBar. What you need to do is to:

  • 實現一個函數(或類方法),您將傳遞給 FTP.retrbinary 作為 callback 而不是 file.write.該函數應該執行 file.write 并更新進度條.

  • Implement a function (or a class method) that you will pass to FTP.retrbinary as callback instead of file.write. The function should do file.write and also update the progress bar.

您還需要知道 ProgressBarmaxval 參數的文件/傳輸的大小.為此,您可以使用 FTP.size.

You also need to know size of the file/transfer for maxval argument of ProgressBar. For that you can use FTP.size.

一個簡單的實現是這樣的:

A trivial implementation is like:

local_path = "archive.zip"
remote_path = "/remote/path/archive.zip"

file = open(local_path, 'wb')

size = ftp.size(remote_path)

pbar = ProgressBar(widgets=widgets, maxval=size)
pbar.start()

def file_write(data):
   file.write(data) 
   global pbar
   pbar += len(data)

ftp.retrbinary("RETR " + remote_path, file_write)

現在你得到了你想要的進度條:

And now you get the progress bar you want:

Downloading:  72% [##############################           ] ETA:   0:00:00 242.1 MiB/s


其他人注意:OP 代碼使用 progressbar2 庫.

PyQt 實現:從另一個運行 FTP 下載的線程更新 PyQt 進度.

這篇關于在 Python 中顯示 FTP 下載進度(ProgressBar)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why I cannot make an insert to Python list?(為什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的開頭(最左端)插入一列)
Python psycopg2 not inserting into postgresql table(Python psycopg2 沒有插入到 postgresql 表中)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不僅將列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 將 Python 中的元素添加到列表末尾?)
TypeError: #39;float#39; object is not subscriptable(TypeError:“浮動對象不可下標)
主站蜘蛛池模板: 成人黄色在线 | 欧美一级黄色片免费观看 | 中文字幕 在线观看 | 国产精品色 | 欧美精品一区在线观看 | 亚洲一区二区三区在线播放 | 亚洲视频在线看 | 久久久久免费 | 成人精品国产一区二区4080 | 欧美精品三区 | 日韩免费一二三区 | 日日夜夜精品免费视频 | 国产乱一区二区三区视频 | 亚洲欧洲精品一区 | 日日操夜夜操天天操 | 日本成人在线观看网站 | 精品久久网| 99影视 | 亚洲男人的天堂网站 | 国产激情在线 | 天天干天天干 | 日本在线视频一区二区 | 欧美精品一区在线 | 久久亚洲精品视频 | 亚洲视频免费一区 | 亚洲国产一区二区三区 | 亚洲精品一区二区三区在线 | 日韩免费福利视频 | 91久久精 | 精品日韩在线 | 精品视频久久久久久 | 欧美日韩综合 | 日本一二区视频 | 国产一级视屏 | 犬夜叉在线观看 | 欧美视频一区二区三区 | 成人精品一区二区 | 99久久婷婷国产综合精品电影 | 国产精品免费一区二区 | 一区二区视频 | 五月婷婷丁香婷婷 |