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

通過 FTP 確定列表是否是 Python 中的目錄或文件

Determine if a listing is a directory or file in Python over FTP(通過 FTP 確定列表是否是 Python 中的目錄或文件)
本文介紹了通過 FTP 確定列表是否是 Python 中的目錄或文件的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

Python 有一個(gè)標(biāo)準(zhǔn)庫模塊 ftplib 來運(yùn)行 FTP 通信.它有兩種獲取目錄內(nèi)容列表的方法.一,FTP.nlst(),將返回一個(gè)目錄的內(nèi)容列表給定一個(gè)目錄名稱作為參數(shù).(如果給定文件名,它將返回文件名.)這是一種列出目錄內(nèi)容的可靠方法,但不提供任何指示列表中的每個(gè)項(xiàng)目是文件還是目錄.另一種方法是 FTP.dir(),它以字符串格式列出作為參數(shù)給出的目錄的目錄內(nèi)容(或文件屬性,給定文件名).

Python has a standard library module ftplib to run FTP communications. It has two means of getting a listing of directory contents. One, FTP.nlst(), will return a list of the contents of a directory given a directory name as an argument. (It will return the name of a file if given a file name instead.) This is a robust way to list the contents of a directory but does not give any indication whether each item in the list is a file or directory. The other method is FTP.dir(), which gives a string formatted listing of the directory contents of the directory given as an argument (or of the file attributes, given a file name).

根據(jù) 上一個(gè)關(guān)于 Stack Overflow 的問題,解析dir()的結(jié)果可能很脆弱(不同的服務(wù)器可能返回不同的字符串).不過,我正在尋找某種方法來僅列出通過 FTP 包含在另一個(gè)目錄中的目錄.據(jù)我所知,在字符串的權(quán)限部分中抓取 d 是我想出的唯一解決方案,但我想我不能保證權(quán)限會(huì)出現(xiàn)在不同服務(wù)器之間的同一個(gè)地方.是否有更強(qiáng)大的解決方案來通過 FTP 識(shí)別目錄?

According to a previous question on Stack Overflow, parsing the results of dir() can be fragile (different servers may return different strings). I'm looking for some way to list just the directories contained within another directory over FTP, though. To the best of my knowledge, scraping for a d in the permissions part of the string is the only solution I've come up with, but I guess I can't guarantee that the permissions will appear in the same place between different servers. Is there a more robust solution to identifying directories over FTP?

推薦答案

不幸的是 FTP 沒有列出文件夾的命令,因此解析從 ftp.dir() 獲得的結(jié)果將是最好的".

Unfortunately FTP doesn't have a command to list just folders so parsing the results you get from ftp.dir() would be 'best'.

一個(gè)簡(jiǎn)單的應(yīng)用程序,假設(shè)來自 ls(不是 windows ftp)的標(biāo)準(zhǔn)結(jié)果

A simple app assuming a standard result from ls (not a windows ftp)

from ftplib import FTP

ftp = FTP(host, user, passwd)
for r in ftp.dir():
    if r.upper().startswith('D'):
        print r[58:]  # Starting point

標(biāo)準(zhǔn) FTP 命令

自定義 FTP 命令

這篇關(guān)于通過 FTP 確定列表是否是 Python 中的目錄或文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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))
主站蜘蛛池模板: 欧美激情三区 | 超碰成人福利 | 在线中文av | 久久艹精品 | 欧美综合一区 | 亚洲视频一区二区三区四区 | 欧美一级淫片bbb一84 | 国产成人免费观看 | 成人av播放 | 亚洲成人免费 | 午夜精品视频 | 99热免费| 荤话粗俗h高h重口 | 啪啪综合网 | 日本黄a三级三级三级 | 欧美 日韩 国产 成人 在线 | 久久三级视频 | 中文字幕日韩视频 | 国产网站视频 | 中文字幕国产 | 欧美视频亚洲视频 | 手机看片国产 | 伊人精品 | 亚洲成人毛片 | 欧美日韩一区二区在线 | 黄色三级视频网站 | 啪啪网站免费 | 精品国产三级 | 日韩精品一区在线观看 | 国产福利一区二区 | 天堂资源网 | 天天综合影院 | 成人特级毛片 | 四川毛片| 免费a在线 | 日本丰满肉感bbwbbwbbw | 欧美日韩在线视频观看 | 日韩不卡一区二区 | 亚洲小说欧美激情另类 | 偷拍一区二区三区 | 久草视频在线播放 |