从 ftp 下载时 Curl 冻结

Ksh*_*rma 3 ftp curl

我正在尝试使用curl以下命令从 ftp 服务器下载文件:

curl --user kshitiz:pAssword ftp://@11.111.11.11/myfile.txt -o /tmp/myfile.txt -v
Run Code Online (Sandbox Code Playgroud)

curl 连接到服务器并冻结:

* Hostname was NOT found in DNS cache
*   Trying 11.111.11.11...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to 11.111.11.11 (11.111.11.11) port 21 (#0)
< 220-You Are Attempting To Access a Private
< 220-Network.  Unauthorized Access is Strictly
< 220-Forbidden.  Violators Will be Prosecuted!
< 220-- Management
< 220 This is a private system - No anonymous login
> USER kshitiz
< 331 User kshitiz OK. Password required
> PASS pAssword
< 230-OK. Current directory is /
< 230 4432718 Kbytes used (54%) - authorized: 8192000 Kb
> PWD
< 257 "/" is your current location
* Entry path is '/'
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0> EPSV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0< 229 Extended Passive mode OK (|||10653|)
* Hostname was NOT found in DNS cache
*   Trying 11.111.11.11...
* Connecting to 11.111.11.11 (11.111.11.11) port 10653
  0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0* Connected to 11.111.11.11 (11.111.11.11) port 21 (#0)
> TYPE A
  0     0    0     0    0     0      0      0 --:--:--  0:04:02 --:--:--     0^C
Run Code Online (Sandbox Code Playgroud)

但是,连接ftp和获取文件有效:

Status: Connecting to 11.1.1.11:21...
Status: Connection established, waiting for welcome message...
Response:   220-You Are Attempting To Access a Private
Response:   220-Network.  Unauthorized Access is Strictly
Response:   220-Forbidden.  Violators Will be Prosecuted!
Response:   220-- Management
Response:   220 This is a private system - No anonymous login
Command:    USER kshitiz
Response:   331 User kshitiz OK. Password required
Command:    PASS ******
Response:   230-OK. Current directory is /
Response:   230 4432718 Kbytes used (54%) - authorized: 8192000 Kb
Status: Server does not support non-ASCII characters.
Status: Connected
Status: Starting download of /myfile.txt
Command:    CWD /
Response:   250 OK. Current directory is /
Command:    PWD
Response:   257 "/" is your current location
Command:    TYPE I
Response:   200 TYPE is now 8-bit binary
Command:    PASV
Response:   227 Entering Passive Mode (10,9,4,66,39,139)
Command:    RETR myfile.txt
Response:   150 Accepted data connection
Response:   226-File successfully transferred
Response:   226 0.000 seconds (measured here), 3.39 Kbytes per second
Status: File transfer successful, transferred 1 B in 1 second
Run Code Online (Sandbox Code Playgroud)

TYPE A指挥有什么关系?当 ftp 起作用时,为什么 curl 不起作用?

Ksh*_*rma 6

添加--disable-epsv开关解决了这个问题。

一点解释:

我只是花了好几个小时试图找出奇怪的 FTP 问题。出现问题的方式是登录后,当 FTP 客户端尝试列出目录(或任何其他命令)时,它只会挂起。EPSV 是“扩展的被动模式”,是 FTP 历史被动模式 (PASV) 的更新扩展……最近的 FTP 客户端首先尝试使用 EPSV,然后只有在失败时才使用传统的 PASV。...如果防火墙阻止EPSV,客户端会认为命令成功[并继续等待响应]。

在这里阅读更多。