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

使用 FtpLib 獲取文件夾大小

Get folder size using FtpLib(使用 FtpLib 獲取文件夾大小)
本文介紹了使用 FtpLib 獲取文件夾大小的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 FtpLib (Python) 從 ftp 服務器下載包含文件的文件夾.但我想在開始下載之前知道文件夾的大小.

I'm using FtpLib (Python) to download a folder with files from an ftp server. But I want to know the size of the folder before I start downloading it.

在文檔中我找到了 FTP.size(filename) 但這僅適用于文件而不是文件夾...我可以遍歷文件夾中的所有文件,但該文件夾可能包含子文件夾.

In the documentation I found FTP.size(filename) but that's just for files and not for folders... I could loop through all the files in the folder but it is possible that the folder contains subfolders.

那么有人知道如何使用 FtpLib 獲取文件夾的大小嗎?

So does anyone know how to get the size of the folder using FtpLib?

推薦答案

經過反復試驗,我找到了解決方案.

After some trial and error I found the solution.

它基于 Alex Thorntons 解決方案,但我記住可能存在子文件夾.當是文件夾時,ftp.cwd()命令成功,遞歸調用函數.

It's based on Alex Thorntons solution but I kept in mind that there could be subfolders. When it's a folder, the ftp.cwd() command succeeds and the function is called recursively.

ftp.cwd() 命令拋出錯誤時,它是一個文件,我們可以獲取文件大小.類型設置為I"(圖像),這將強制二進制模式,因為 ftp.size() 命令在 ASCII 模式下是不允許的.

When the ftp.cwd() command throws an error, it was a file and we can get the file size. The type is set to "I" (images), this forces binary mode since the ftp.size() command is not allowed in ASCII mode.

def get_total_size(self, directory):
    size = 0
    for filename in self.ftp.nlst(directory):
        try:
            self.ftp.cwd(filename)
            size += self.get_total_size(filename)
        except:
            self.ftp.voidcmd('TYPE I')
            size += self.ftp.size(filename)
    return size

這篇關于使用 FtpLib 獲取文件夾大小的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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:“浮動對象不可下標)
主站蜘蛛池模板: 天堂一区二区三区四区 | 日本淫视频 | av特级毛片 | 欧美久久精品一级c片 | 精品欧美一区二区在线观看 | 91九色视频在线 | 日韩影院一区 | 91精品国产91久久久久游泳池 | 中文字幕亚洲视频 | 91久久久久久久久 | 少妇诱惑av | 国产夜恋视频在线观看 | 亚洲成人一级片 | 亚洲电影一区二区三区 | 久久久免费电影 | 91久久国产综合久久 | 久久久久国产精品一区二区 | 成人影视网址 | 99久久精品一区二区毛片吞精 | 久久久精品视频一区二区三区 | 国产精品污www一区二区三区 | 欧美精品福利视频 | 欧美一区免费 | 别c我啊嗯国产av一毛片 | 日本黄色大片免费 | www97影院| 淫片专区 | 手机看片在线播放 | 成人精品国产一区二区4080 | 国产福利在线小视频 | 久久在线看 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 欧美涩| 在线观看成人免费视频 | www.成人免费视频 | 久久久福利| 999热在线视频 | 日韩精品一区二区三区中文在线 | 欧美一区二区三区久久精品 | 亚洲国产成人精品久久久国产成人一区 | 成年人黄色一级毛片 |