to upload a file to ftp

Am trying to upload a file to ftp using culr but can’t seem to set the file to upload.
Managed to log in and get a (0) response, that I think it means it logs.
But am not able to upload a file at all.
This is supposed to be a remote back up for an inventory file, that will be some sort of database flat file at some point.
Has anyone used curl to upload to ftp ?

Have you seen this sample?

Thanks for pointing that out.
Can’t seem to get this working:

var long:Int64 = 1;
curl.setOption(UPLOAD, long);

It says it must be a long and notation is 1L to put curl in upload mode, but it isn’t working.
Do I have to use some sort of special type to get it to upload mode ? It obviously isn’t Int64… but I don’t know what it should be though.

It appears that UPLOAD is implemented as a Bool in Lime

That’s even more confusing, because I tried set it to true like verbose mode and the moment that’s in there it starts throwing “CURLE_URL_MALFORMAT (3) The URL was not properly formatted.”.
Which is odd because I manage to log with the same information on the previous curl.perform().
Or maybe I’m not even logging. Well, 5 hours of this here I come, I’ll report back.

CURLOPT_URL is set already?

Like this: curl.setOption(URL, “”);

Does it need an “ftp://” prefix? Perhaps not?

Did you set CURLOPT_READDATA with Haxe Bytes?

I set : curl.setOption(READDATA, hd_src);
with : var hd_src:String =‘testfile.tst’);

is that what I’m messing up ?

Please try File.getBytes and see if that helps?

Tried File.getBytes like this:

var hd_src:Bytes = File.getBytes(‘necurl.ndll’);
var fsize:sys.FileStat = sys.FileSystem.stat(‘necurl.ndll’);

then I do:
var curl:CURL = new CURL();
curl.setOption(CONNECTTIMEOUT, 30);
curl.setOption(TRANSFERTEXT, 1);
curl.setOption(VERBOSE, true);
curl.setOption(UPLOAD, true);
curl.setOption(URL, “”);
curl.setOption(USERNAME , “phony”);
curl.setOption(PASSWORD, “phony”);
curl.setOption(READDATA, hd_src);
curl.setOption(INFILESIZE, fsize.size);

puts out a (3) error code, mal formatted url.

“ftp://” prefix or not, it seems to work either way.
I get the (0) when just using URL, USERNAME and PASSWORD fields set thought.

If I comment out : curl.setOption(UPLOAD, true); it gives a (0), of course at that point it isn’t doing anything because it is at default I think, which is download mode.

If I pass a string in UPLOAD, like : curl.setOption(UPLOAD, “whatever”); it comes back as (0) too.
Still does nothing, but that somehow passes…

Ok, I think I got it, I had to setup the actual file name you want to pass the bytes into, else it throws badly formatted URL, because it was missing the filename:
curl.setOption(URL, “”);

comes back as (0), the file gets created and all is well.
Sorry, I was being daft about it.
Thanks for helping @singmajesty !

1 Like