martin2250

Download

Jun 20th, 2015
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. local args = {...}
  2. if #args ~= 2 then
  3.     print("usage: download <address> <filename>")
  4. else
  5. local filen = args[2]
  6. local add = args[1]
  7.  
  8. http.request(add)
  9. local requesting = true
  10.  
  11.  while requesting do
  12.  
  13.    local event, url, sourceText = os.pullEvent()
  14.  
  15.    if event == "http_success" then
  16.  
  17.      local respondedText = sourceText.readAll()
  18.  
  19.     local f = fs.open(filen, "w")
  20.     f.write(respondedText)
  21.     f.close()
  22.  
  23.      requesting = false
  24.  
  25.    elseif event == "http_failure" then
  26.  
  27.      print("Server didn't respond.")
  28.  
  29.      requesting = false
  30.  
  31.    end
  32.  end
  33.  end
Add Comment
Please, Sign In to add comment