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

使用 FtpLib 獲取文件夾大小

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

問題描述

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

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?

推薦答案

經(jīng)過反復(fù)試驗(yàn),我找到了解決方案.

After some trial and error I found the solution.

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

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.

當(dāng) ftp.cwd() 命令拋出錯(cuò)誤時(shí),它是一個(gè)文件,我們可以獲取文件大小.類型設(shè)置為I"(圖像),這將強(qiáng)制二進(jìn)制模式,因?yàn)?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

這篇關(guān)于使用 FtpLib 獲取文件夾大小的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

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:“浮動(dòng)對(duì)象不可下標(biāo))
主站蜘蛛池模板: 久久精品综合 | 日韩三级精品 | 日韩精品久久久 | 一级久久| 97人人爱 | 小sao货撅起屁股扒开c微博 | 男人午夜影院 | 黄色片中文字幕 | 亚洲精品国产精品国自产观看浪潮 | 黄色大片免费观看 | 狠狠五月| 欧美一区二区三区在线视频 | 欧美日韩二区三区 | 国产精品免费一区二区 | 国产精品成人免费精品自在线观看 | 国产不卡视频在线观看 | 手机av免费 | 91久久综合| 操操操av | 中文字幕在线看片 | 综合伊人久久 | 黄色一级大片在线免费看国产一 | 国产精品美女久久 | 亚洲av毛片成人精品 | 久久艹精品 | 日韩一级免费视频 | 亚洲精品www久久久久久广东 | 综合久久99| 欧美日韩一 | 国内av在线 | 中文字幕在线观看亚洲 | 夜夜操天天| 免费a在线| 黄色免费在线视频 | 天天干狠狠干 | 奇米狠狠干 | 成人精品免费视频 | 欧美日韩在线观看视频 | 日韩av一区二区三区四区 | 欧美天堂在线 | 天堂在线视频 |