iPeer

Untitled

Feb 3rd, 2013
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. local function help()
  2.     print("Usage:")
  3.     print("aget <postname> <name>");
  4. end
  5.  
  6. local tArgs = { ... }
  7.  
  8. if #tArgs < 2 or tArgs[1] == "help" then
  9.     help()
  10.     return
  11. end
  12.  
  13. if not http then
  14.     print( "AGET requires http API" )
  15.     return
  16. end
  17.  
  18. local id = tArgs[1]
  19. local fname = tArgs[2]
  20. local sFile = shell.resolve(fname)
  21.  
  22. if fs.exists(sFile) then
  23.     print("File already exists.")
  24.     return
  25. end
  26.  
  27. write("Attempting to connect to ipeer.auron.co.uk...")
  28. local r = http.get("http://ipeer.auron.co.uk/ftb/scripts/"..textutils.urlEncode(id))
  29. if r then
  30.     print("OK.")
  31.     local sr = r.readAll()
  32.     r.close()
  33.     local f = fs.open(sFile, "w")
  34.     f.write(sr)
  35.     f.close()
  36.     print ("Saved as "..fname)
  37. else
  38.     print("Failed.")
  39. end
Advertisement
Add Comment
Please, Sign In to add comment