Task
Connect to a server, change directory, list its contents and download a file as binary using the FTP protocol. Use passive mode if available.




without js -- libcurl, allocate, file i/o
include libcurl.e
constant url = "ftp://speedtest.tele2.net/"
 
curl_global_init()
atom curl = curl_easy_init(),
     pErrorBuffer = allocate(CURL_ERROR_SIZE)
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, pErrorBuffer)
curl_easy_setopt(curl, CURLOPT_URL, url)
object res = curl_easy_perform_ex(curl)
if integer(res) then
    ?{res,peek_string(pErrorBuffer)}
else
    puts(1,res)
end if
 
string filename = "1KB.zip"
{} = delete_file(filename)
res = curl_easy_get_file(url&filename, "", filename) 
if res=CURLE_OK then
    printf(1,"successfully downloaded %s (size %s)\n",{filename,get_file_size(filename,true)})
else
    ?{"error",res}
end if
