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.




CURLOPT_URL = 10002
ch = xtra("Curl").new()
url = "ftp://domain.com"
 
-- change to remote dir "/foo/bar/"
put "/foo/bar/" after url
 
ch.setOption(CURLOPT_URL, url)
res = ch.exec(1)
 
-- print raw FTP listing as string
put res.readRawString(res.length)
 
-- download file "download.mp3" (passive mode is the internal default behavior)
filename = "download.mp3"
ch.setOption(CURLOPT_URL, url & filename)
ch.setDestinationFile(_movie.path & filename)
res = ch.exec()