Download file from ftp with curl

I’m able do upload to ftp with lime.net.curl.CURL but I’m missing something while trying to download.
Probably the place to name where the download file is going to be created.
If I turn verbose to true it says it downloaded (though there’s a Maxdownload = -1 showing up…)
I get (some stuff changed for privacy):

  • Trying 188.ip.is.here…
  • TCP_NODELAY set
  • Connected to ftp.name.com (188.ip.is.here) port 21 (#0)
    220---------- Welcome to FTPd [privsep] [TLS] ----------
    220-You are user number 17 of 50 allowed.
    220-Local time is now 17:35. Server port: 21.
    220-This is a private system - No anonymous login
    USER myuser
    331 User myuser OK. Password required
    PASS mypass
    230-OK. Current restricted directory is /
    230 97 Kbytes used (0%) - authorized: 1024000 Kb
    PWD
    257 “/” is your current location
  • Entry path is ‘/’
    CWD teste
  • ftp_perform ends with SECONDARY: 0
    250 OK. Current directory is /teste
    EPSV
  • Connect data stream passively
    229 Extended Passive mode OK (|||52390|)
  • Trying 188.ip.is.here…
  • TCP_NODELAY set
  • Connecting to 188.ip.is.here (188.ip.is.here) port 52390
  • Connected to ftp.name.com (188.ip.is.here) port 21 (#0)
    TYPE I
    200 TYPE is now 8-bit binary
    SIZE desktop.ini
    213 282
    RETR desktop.ini
    150 Accepted data connection
  • Maxdownload = -1
  • Getting file with size: 282

    [ . S h e l l C l a s s I n f o ]
    L o c a l i z e d R e s o u r c e N a m e = @ % S y s t e m R o o t % \ s y s t e m 3 2 \ s h e l l 3 2 . d l l , 2 1 7 6 9
    I c o n R e s o u r c e = % S y s t e m R o o t % \ s y s t e m 3 2 \ i m a g e r e s . d l l , - 1 8 3
  • Remembering we are in dir “teste/”
    226-File successfully transferred
    226 0.002 seconds (measured here), 154.98 Kbytes per second
  • Connection #0 to host ftp.name.com left intact

when I do:

var curl:CURL = new CURL();
curl.reset();
curl.setOption(CONNECTTIMEOUT, 30);
curl.setOption(VERBOSE, true);
curl.setOption(URL, “ftp://ftp.name.com/teste/desktop.ini”);
curl.setOption(USERPWD , “myuser:mypass”);
curl.perform();

So basically file “desktop.ini” is being “downloaded” to console, I just don’t know where to or how to direct it to some place. Some way I can set that, been going through docs but didn’t find it.

Have you tried setting the WRITEFUNCTION option?

It should call once at the end of the request (due to HXCPP garbage collection issues with more frequent callbacks) unless you use CURLMulti which has the ability to send updates

1 Like

Added just before curl.perform() : curl.setOption(WRITEFUNCTION, testfile);

and:
function testfile(e,f)
{
sys.io.File.saveContent(‘downloaded.txt’,f);
}

That fixed it.
Thanks for pointing out the fix @singmajesty

1 Like