1. --!movie
  2. --!encoding=utf-8
  3.  
  4. global $
  5.  
  6. global gCh
  7.  
  8. ----------------------------------------
  9. -- Upload file with ftp (asynchronous/non-blocking mode)
  10. -- Show progress info
  11. ----------------------------------------
  12. on startMovie
  13.     _player.debugPlaybackEnabled = 1
  14.  
  15.     -- libs
  16.     $.import("curl")
  17.     $.import("file")
  18.  
  19.     -- config
  20.     tLocalFile = $.PATH & "test.mp3"
  21.     tRemoteFile = "ftp://domain.com/test/ftp_upload.lsw"
  22.     tUsername = "john.doe"
  23.     tPassword = "********"
  24.  
  25.     -- get a CURL handle (xtra instance)
  26.     gCh = $.curl.init()
  27.  
  28.     -- specify options
  29.     gCh.setOption($.curl.CURLOPT.URL, tRemoteFile)
  30.  
  31.     gCh.setOption($.curl.CURLOPT.USERNAME, tUsername)
  32.     gCh.setOption($.curl.CURLOPT.PASSWORD, tPassword)
  33.  
  34.     gCh.setOption($.curl.CURLOPT.UPLOAD, 1)
  35.     gCh.setOption($.curl.CURLOPT.NOPROGRESS, 0)
  36.  
  37.     -- without this call <ultotal> in progressCallback isn't populated!
  38.     gCh.setOption($.curl.CURLOPT.INFILESIZE, $.file.size(tLocalFile))
  39.  
  40.     -- upload source
  41.     gCh.setSourceFile(tLocalFile)
  42.  
  43.     -- set callbacks
  44.     gCh.setProgressCallback(#slotCurlProgress)
  45.  
  46.     $.curl.execAsyncDetached(gCh, #slotCurlResult)
  47. end
  48.  
  49. ----------------------------------------
  50. -- @callback
  51. ----------------------------------------
  52. on slotCurlResult (res)
  53.     put "UPLOAD FINISHED!"
  54.     put "ERROR:" && curl_error(res) -- if returnMode=0, res is ALWAYS an error code
  55.  
  56.     --put "SPEED_UPLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_UPLOAD)
  57.     --put "TOTAL_TIME:" && gCh.getInfo($.curl.CURLINFO.TOTAL_TIME)
  58.  
  59.     gCh = VOID
  60. end
  61.  
  62. ----------------------------------------
  63. -- @callback
  64. ----------------------------------------
  65. on slotCurlProgress (dltotal, dlnow, ultotal, ulnow)
  66.     -- put dltotal, dlnow, ultotal, ulnow
  67.     if ultotal>0 then
  68.         put (ulnow*100/ultotal) && "%"
  69.     end if
  70. end
  71.  
[raw code]