我正在尝试使用以下命令从 ftp 服务器下载文件curl
:
curl --user kshitiz:pAssword ftp://@11.111.11.11/myfile.txt -o /tmp/myfile.txt -v
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
然而,连接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
命令有什么关系TYPE A
?为什么 ftp 可以工作时,curl 却不起作用?
答案1
添加--disable-epsv
开关解决了问题。
一点解释:
我刚刚花了很多时间试图解决奇怪的 FTP 问题。问题出现的方式是,登录后,当 FTP 客户端尝试列出目录(或任何其他命令)时,它就会挂起。 EPSV 是“扩展被动模式”,是 FTP 历史被动模式 (PASV) 的更新扩展...最近的 FTP 客户端首先尝试 EPSV,然后仅在失败时才使用传统的 PASV。 ...如果防火墙阻止 EPSV,客户端会认为命令成功[并继续等待回复]。
阅读更多这里。
答案2
使用 conections/users/passwords 创建 ~/.netrc 后的“此处”文档示例。
#!/bin/bash
ftp 11.1.1.11 << eof
ascii
get /tmp/myfile.txt
bye
eof
遗憾的是你不能使用lftp,它是一个很棒的客户端,如果你给它正确的权限,我没有看到将密码放在 ~/.netrc 中或将它们放在脚本中之间有任何安全差异。
答案3
问题出在 11.111.11.11 IP 地址上运行的 ftp 服务器上。
这个就永远挂了...
FTP 11.111.11.11
首先让您的 ftp 服务器与一个简单的 ftp 客户端一起工作。
这可能也会修复你的curl命令。