bash 使用 cURL 列出目录中的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47400414/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:36:31  来源:igfitidea点击:

Listing files in a directory using cURL

bashcurl

提问by David Dennis

Is there a common practice to list the files in a directory using cURL? right now i'm doing this to get a single file:

是否有使用 cURL 列出目录中的文件的常见做法?现在我这样做是为了得到一个文件:

curl -O -vvv -k -u user:password https://myURL/ws/myfile.zip

The thing is sometimes I wont know my file name and I know cURL is not wildcard friendly. Is there a common practice for getting all files within a directory? Or just printing them out so I can find the .zip and curl using that? I know wget has a option but I would prefer to use cURL.

问题是有时我不知道我的文件名,而且我知道 cURL 不是通配符友好的。是否有获取目录中所有文件的常见做法?或者只是将它们打印出来以便我可以使用它找到 .zip 和 curl?我知道 wget 有一个选项,但我更喜欢使用 cURL。

回答by John Moon

There's no easy way to get a directory listing using HTTP. You can use curl to just print the HTML generated by the site. If there's an index with links to the files on that server, simply running

没有简单的方法可以使用 HTTP 获取目录列表。您可以使用 curl 来打印站点生成的 HTML。如果有指向该服务器上文件链接的索引,只需运行

curl -s -u user:password https://myURL/ws/ | grep .zip

curl -s -u user:password https://myURL/ws/ | grep .zip

will print HTML-formatted links to the zip files available for download on that page.

将打印可在该页面上下载的 zip 文件的 HTML 格式链接。