1. --!movie
  2. --!encoding=utf-8
  3.  
  4. global $
  5.  
  6. global gCh
  7.  
  8. ----------------------------------------
  9. -- Download 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.  
  18.     -- config
  19.     tRemoteFile = "ftp://ftp.fu-berlin.de/pub/du-k.gz"
  20.     tLocalFile = $.PATH & "du-k.gz"
  21.  
  22.     -- get a CURL handle (xtra instance)
  23.     gCh = $.curl.init()
  24.  
  25.     -- specify options
  26.     gCh.setOption($.curl.CURLOPT.URL, tRemoteFile)
  27.  
  28.     --gCh.setOption($.curl.CURLOPT.USERNAME, tUsername)
  29.     --gCh.setOption($.curl.CURLOPT.PASSWORD, tPassword)
  30.  
  31.     gCh.setOption($.curl.CURLOPT.NOPROGRESS, 0)
  32.  
  33.     gCh.setDestinationFile(tLocalFile)
  34.     gCh.setProgressCallback(#slotCurlProgress)
  35.  
  36.     $.curl.execAsyncDetached(gCh, #slotCurlResult)
  37. end
  38.  
  39. ----------------------------------------
  40. -- @callback
  41. ----------------------------------------
  42. on slotCurlResult (res)
  43.     put "DOWNLOAD FINISHED!"
  44.     put "ERROR:" && curl_error(res) -- if returnMode=0, res is ALWAYS an error code
  45.  
  46.     --put "SPEED_DOWNLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_DOWNLOAD)
  47.     --put "TOTAL_TIME:" && gCh.getInfo($.curl.CURLINFO.TOTAL_TIME)
  48.  
  49.     gCh = VOID
  50. end
  51.  
  52. ----------------------------------------
  53. -- @callback
  54. ----------------------------------------
  55. on slotCurlProgress (dltotal, dlnow, ultotal, ulnow)
  56.     --put dltotal, dlnow, ultotal, ulnow
  57.     if dltotal>0 then
  58.         put (dlnow*100/dltotal) && "%"
  59.     end if
  60. end
  61.  
[raw code]