3

I'm trying to download a file from ftp server using curl:

curl --user kshitiz:pAssword ftp://@11.111.11.11/myfile.txt -o /tmp/myfile.txt -v

curl connects to the server and freezes:

* 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

Connecting with ftp and fetching a file works however:

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

What's the deal with the TYPE A command? Why doesn't curl work when ftp does?

  • Forgive my ignorance but.... what makes you want to access an ftp with something like curl or wget? – YoMismo Jul 16 '15 at 15:18
  • 1
    @YoMismo Non-interactive script-able ftp access. – Kshitiz Sharma Jul 16 '15 at 15:23
  • 1
    You can use ftp for that matter. Create a .netrc file in your home directory with the next format: machine 11.1.1.11 login kshitiz password pAssword after that you will be able to acces your ftp with 'here' document scritping and without user/password. – YoMismo Jul 16 '15 at 15:25
  • You can also use lftp which is a great client for ftp/ftps/sftp connections and will allow you to automate scripts with it and 'here' documents. – YoMismo Jul 16 '15 at 15:26
  • For curl's debugging purposes, maybe if you substitute -v with --trace you get more information about what's going on. – YoMismo Jul 16 '15 at 15:42
5

Adding --disable-epsv switch fixed the problem.

A little explanation:

I just went through many hours of trying to figure out wierd FTP problems. The way that the problem presented was that after login, when the FTP client attempted a directory listing (or any other command), it would just hang. EPSV is "extended passive mode", and is a newer extension to FTP's historical passive mode (PASV) ... most recent FTP clients attempt EPSV first, and then only use the traditional PASV if it fails. ... if the firewall is blocking EPSV, the client will think that the command is successful [and keep waiting for response].

Read more here.

  • Wow well done for finding this, it had me scratching my head when a script kept stopping on curl ftp downloads! – Cas Sep 11 '18 at 14:54
  • To set this as curl default: echo no-epsv >> ~/.curlrc – Cas Sep 11 '18 at 15:01
1

Example of 'here' document after creating a ~/.netrc with conections/users/passwords.

 #!/bin/bash
 ftp 11.1.1.11 << eof
        ascii
        get /tmp/myfile.txt
        bye
 eof

Pitty you can't use lftp, it's a great client and I don't see any security difference between having your passwords in ~/.netrc or having them in the script if you give it the right permissions.

  • +1 For posting a viable alternative solution but there's a way to make curl work as well. – Kshitiz Sharma Jul 16 '15 at 16:51
0

Problem is with the ftp server running on 11.111.11.11 IP address.

This hangs forever...

ftp 11.111.11.11

First get your ftp server working with a simple ftp client.

Likely this will fix your curl command too.

  • Didn't I already mention that it works with FileZilla? – Kshitiz Sharma Jul 16 '15 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.