久久久久久久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:“浮動對象不可下標)
主站蜘蛛池模板: 黄网站涩免费蜜桃网站 | 国产精品一区在线 | 国产69久久精品成人看动漫 | 国产1区| 久久草在线视频 | 亚洲精品欧洲 | 久久国 | 日韩三区 | 国产精品一区二区欧美黑人喷潮水 | 99pao成人国产永久免费视频 | 国产亚洲精品久久久久久豆腐 | 亚洲精选一区二区 | 99免费在线观看 | 久久久久久亚洲国产精品 | 日本 欧美 国产 | 日本高清不卡视频 | 综合五月婷 | 99精品免费久久久久久日本 | 亚洲精品久久久久久首妖 | 美女黄色在线观看 | 婷婷丁香综合网 | 国产日韩亚洲欧美 | 不卡一区二区三区四区 | 不卡av在线| 一区二区三区影院 | 国产精产国品一二三产区视频 | 久草新在线 | 欧美在线视频一区二区 | 亚洲成人一二三 | 精品一区二区三区中文字幕 | 奇米在线 | 精久久久久 | 精品一区二区三区四区在线 | 免费视频一区二区 | 中文字幕 国产 | 久久精品—区二区三区 | 免费在线精品视频 | 日韩国产在线 | 国产不卡视频在线 | 日韩精品一区二区三区 | 日韩一区二区在线视频 |