Guest User

weGet

a guest
Dec 29th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.78 KB | None | 0 0
  1. tArgs = { ... }
  2.  
  3. function help()
  4.   print("weGet <URL> <file>")
  5. end
  6.  
  7. if http then
  8.   if #tArgs < 1 then
  9.     help()
  10.     error("Missing file URL")
  11.   elseif #tArgs < 2 then
  12.     help()
  13.     error("Missing saved file name")  
  14.   elseif #tArgs > 2 then
  15.     help()
  16.     error("Too much arguments")
  17.   else
  18.     print("Trying to get " .. tArgs[2] .. " from " .. tArgs[1])
  19.     file = http.get(tArgs[1])
  20.     if file == nil then
  21.       error("There's no such file")
  22.     else
  23.       print("Got " .. tArgs[2])
  24.      
  25.       saved = fs.open(shell.resolve("") .. "/" .. tArgs[2], "w")
  26.       saved.write(file.readAll())
  27.       saved.close()
  28.      
  29.       print("Successfully saved the file!")
  30.      
  31.       file  = nil
  32.       saved = nil
  33.     end
  34.   end
  35. else
  36.   error("weGet needs HTTP!")
  37. end
Advertisement
Add Comment
Please, Sign In to add comment