使用curl下载ftp文件,无需遍历父目录

使用curl下载ftp文件,无需遍历父目录,curl,ftp,Curl,Ftp,我想从ftp服务器下载文件。我已经确认我有访问权限,因为我可以使用Chrome手动下载文件,列出ftp目录内容,然后单击每个文件,一次下载一个文件。不过,有很多文件,我想用curl来帮我抓取它们 但是,ftp服务器的设置使我无法访问父目录,即使我可以访问子目录,因此下面的curl命令失败: curl -u username:password "ftp://example.com/Parent/Child/file.txt" -o file.txt 详细(-v)输出的关键摘录: PWD *输入路

我想从ftp服务器下载文件。我已经确认我有访问权限,因为我可以使用Chrome手动下载文件,列出ftp目录内容,然后单击每个文件,一次下载一个文件。不过,有很多文件,我想用curl来帮我抓取它们

但是,ftp服务器的设置使我无法访问
父目录
,即使我可以访问
子目录
,因此下面的
curl
命令失败:

curl -u username:password "ftp://example.com/Parent/Child/file.txt" -o file.txt
详细(
-v
)输出的关键摘录:

<230用户已登录。
>PWD
*输入路径为“/”
>CWD父代
<550访问被拒绝
*服务器拒绝您更改到给定目录
curl:(9)服务器拒绝您更改到给定目录

有没有办法让curl直接更改到最终目录,而不是遍历层次结构,以避免在不允许的父目录上出错?

是的,可以。Curl通过拆分每个
/
字符上的路径来工作,然后一次发出一个
PWD
命令(从详细输出中可以看到)

只需使用
%2f
对中间
/
字符进行URL编码,curl将立即发出
CWD
命令:

$ curl -u username:password "ftp://example.com/Parent%2fChild/file.txt" -o file.txt

> CWD Parent/Child
< 250 CWD command successful.
$curl-u用户名:密码”ftp://example.com/Parent%2fChild/file.txt“-o file.txt
>家长/子女
<250 CWD命令成功。

是的,你可以。Curl通过拆分每个
/
字符上的路径来工作,然后一次发出一个
PWD
命令(从详细输出中可以看到)

只需使用
%2f
对中间
/
字符进行URL编码,curl将立即发出
CWD
命令:

$ curl -u username:password "ftp://example.com/Parent%2fChild/file.txt" -o file.txt

> CWD Parent/Child
< 250 CWD command successful.
$curl-u用户名:密码”ftp://example.com/Parent%2fChild/file.txt“-o file.txt
>家长/子女
<250 CWD命令成功。