我想从ftp服务器下载文件。我已经确认我有访问权限,因为我可以手动下载文件,使用Chrome列出ftp目录内容,然后单击每个文件,一次下载一个。不过,有很多文件,我想使用curl为我获取所有这些文件。
但是,ftp服务器的设置使我没有访问Parent目录的权限,即使我有访问Child目录的权限,因此以下curl命令失败:
curl -u username:password "ftp://example.com/Parent/Child/file.txt" -o file.txt详细(-v)输出中的关键摘录:
< 230 User logged in.
> PWD
* Entry path is '/'
> CWD Parent
< 550 Access is denied
* Server denied you to change to the given directory
curl: (9) Server denied you to change to the given directory有没有办法让curl直接更改到最终目录,而不是遍历层次结构,以避免它在不允许的父目录上给出错误?
发布于 2016-01-16 02:37:20
可以,停那儿吧。Curl的工作方式是在每个/字符上拆分路径,然后每次发出一个PWD命令(从详细输出中可以看到)。
只需使用%2f对中间/字符进行urlencode,curl将一次性发出CWD命令:
$ curl -u username:password "ftp://example.com/Parent%2fChild/file.txt" -o file.txt
> CWD Parent/Child
< 250 CWD command successful.瞧!
https://stackoverflow.com/questions/34817601
复制相似问题