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

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

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

問題描述

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

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).

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

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() 獲得的結果將是最好的".

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

一個簡單的應用程序,假設來自 ls(不是 windows ftp)的標準結果

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

標準 FTP 命令

自定義 FTP 命令

這篇關于通過 FTP 確定列表是否是 Python 中的目錄或文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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在线视频观看 | 四虎影院新地址 | 日韩一区二区三区在线观看 | 五月精品视频 | 国产精品7777777 | 日韩在线中文字幕 | 国产一二三区免费视频 | 天天人人精品 | 国产精品久久av | 三级成人在线 | 国产精品久久久久久亚洲调教 | 国产精品99久久久久久宅男 | 国产精品视频免费观看 | 中文字幕专区 | 欧美日韩精品一区 | 日韩在线一区二区三区 | 国产精品久久久久无码av | 一区二区三区欧美 | 91亚洲精品国偷拍自产在线观看 | 天堂成人国产精品一区 | 色资源站| 亚洲一二三在线观看 |