--!movie
--!encoding=utf-8
global $
global gCh
----------------------------------------
-- Upload file with ftp (asynchronous/non-blocking mode)
-- Show progress info
----------------------------------------
on startMovie
_player.debugPlaybackEnabled = 1
-- libs
$.import("curl")
$.import("file")
-- config
tLocalFile = $.PATH & "test.mp3"
tRemoteFile = "ftp://domain.com/test/ftp_upload.lsw"
tUsername = "john.doe"
tPassword = "********"
-- get a CURL handle (xtra instance)
gCh = $.curl.init()
-- specify options
gCh.setOption($.curl.CURLOPT.URL, tRemoteFile)
gCh.setOption($.curl.CURLOPT.USERNAME, tUsername)
gCh.setOption($.curl.CURLOPT.PASSWORD, tPassword)
gCh.setOption($.curl.CURLOPT.UPLOAD, 1)
gCh.setOption($.curl.CURLOPT.NOPROGRESS, 0)
-- without this call <ultotal> in progressCallback isn't populated!
gCh.setOption($.curl.CURLOPT.INFILESIZE, $.file.size(tLocalFile))
-- upload source
gCh.setSourceFile(tLocalFile)
-- set callbacks
gCh.setProgressCallback(#slotCurlProgress)
$.curl.execAsyncDetached(gCh, #slotCurlResult)
end
----------------------------------------
-- @callback
----------------------------------------
on slotCurlResult (res)
put "UPLOAD FINISHED!"
put "ERROR:" && curl_error(res) -- if returnMode=0, res is ALWAYS an error code
--put "SPEED_UPLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_UPLOAD)
--put "TOTAL_TIME:" && gCh.getInfo($.curl.CURLINFO.TOTAL_TIME)
gCh = VOID
end
----------------------------------------
-- @callback
----------------------------------------
on slotCurlProgress (dltotal, dlnow, ultotal, ulnow)
-- put dltotal, dlnow, ultotal, ulnow
if ultotal>0 then
put (ulnow*100/ultotal) && "%"
end if
end