久久久久久久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网页| 黄a网站| 欧美在线视频一区二区 | 久久不卡 | 日韩在线免费视频 | 神马福利 | 久草视频观看 | 亚洲免费婷婷 | 麻豆亚洲 | 成人小视频在线观看 | 国产精品视频免费观看 | 伊色综合久久之综合久久 | 一区二区三区不卡视频 | 欧美精品99 | 九九伊人sl水蜜桃色推荐 | 一级在线毛片 | 国产精品美女久久久久aⅴ国产馆 | 另类视频在线 | 国产激情亚洲 | 午夜一级大片 | 高清色视频 | 亚洲第一天堂 | 欧美性猛交一区二区三区精品 | 日韩欧美一区二区三区免费观看 | 国产精品美女久久久久aⅴ国产馆 | 国产丝袜一区二区三区免费视频 | 自拍偷拍小视频 | 蜜月aⅴ免费一区二区三区 99re在线视频 | 国产精品色 | 欧美人成在线视频 | 浴室洗澡偷拍一区二区 | 国产一区2区 | 国产亚洲一区二区三区 |