Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. local function printUsage()
  2.     print( "Usages:" )
  3.     print( "downloadFile <url_file> <name>")
  4. end
  5.  
  6. local tArgs = { ... }
  7.  
  8. if #tArgs < 2 then
  9.     printUsage()
  10.     return
  11. end
  12.  
  13. if not http then
  14.     printError( "DownloadFile Api require http Api" )
  15. end
  16.  
  17. local function get(url)
  18.     print( "Connecting to " .. url)
  19.     local response = http.get(url)
  20.     if response then
  21.         print( "Success to connect at " .. url)
  22.         local sResponse = response.readAll()
  23.         reponse.close()
  24.         return sResponse
  25.     else
  26.         printError( "Failed to load " .. url)
  27.     end
  28. end
  29.  
  30. local function writeFile( url, nameFile )
  31.     if url then
  32.         local reponse = get(url)
  33.         local file = fs.open(nameFile, "w")
  34.         file.write(reponse)
  35.         file.close()
  36.     end
  37. end
  38.  
  39. if #tArgs == 3 then
  40.     writeFile(tArgs[1], tArgs[2])
  41. elseif #tArgs == 2 then
  42.     writeFile(tArgs[1], tArgs[1])
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement