Linux FTP 命令仅列出目录。不可能的?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9529335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FTP command to List only directories. Impossible?
提问by Roy
How do I perform directory listing but only display directories?
如何执行目录列表但只显示目录?
I tried ls | grep '/'but it got rejected with the error : usage: ls remote-directory local-file
我试过ls | grep '/'但它因错误而被拒绝: 用法:ls remote-directory local-file
This is because command line in FTP is different than your usual linux command line, but I was wondering if there is something equivalent in FTP command
这是因为 FTP 中的命令行与您通常的 linux 命令行不同,但我想知道 FTP 命令中是否有等效的东西
Thanks in advance
提前致谢
回答by mweerden
The FTP protocol does not directly support such a feature. It does, however, allow for a broad interpretation that some servers use to accept things like using ls
-style arguments (e.g. LIST -d
, as mentioned by bdk).
FTP 协议不直接支持这样的功能。然而,它确实允许广泛的解释,一些服务器用来接受诸如使用ls
-style 参数之类的东西(例如LIST -d
,如 bdk 所提到的)。
Without such a broad interpretation by the server, you are left with retrieving this information from the listing. Unfortunately the standard doesn't provide a fixed format for this either (although it seems most servers use the ls -l
formatting).
如果服务器没有如此广泛的解释,您只能从列表中检索此信息。不幸的是,标准也没有为此提供固定格式(尽管似乎大多数服务器都使用这种ls -l
格式)。
回答by MutantTurkey
using just ftp itself can be an issue, but if you pipe the output to a shell you'll have less of an issue.
仅使用 ftp 本身可能是一个问题,但如果您将输出通过管道传输到 shell,那么问题就会减少。
ftp -i myhost.com/yolo/ <<< "ls -1R all_files_list.txt"
we can see each listng in that file contains the file permissions signature like "-rwxrwxrw". a little bit of looking and you'll se that all directories start with 'd'
我们可以看到该文件中的每个列表都包含文件权限签名,如“-rwxrwxrw”。稍微看一下,您会发现所有目录都以“d”开头
so
所以
grep '^d' all_files_list.txt > only_directories_list.txt