Advertisement
Stiepen

CC WGet

Dec 1st, 2012
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.60 KB | None | 0 0
  1. --[[
  2.   Copyright by Kilobyte/Stiepen 2012
  3.  
  4.   This is a quick WGET for ComputerCraft i made.
  5.   if it crashes, make sure HTTP api is enabled.
  6. --]]
  7.  
  8. local tArgs = {...}
  9. function main()
  10.   local h = http.get(tArgs[1])
  11.   if not h then
  12.     printError("HTTP ERROR")
  13.     return
  14.   end
  15.   local path = shell.resolve(tArgs[2])
  16.   if fs.exists(path) then
  17.     printError("File already exists")
  18.     return
  19.   end
  20.   local dir = fs.combine(path, "..")
  21.   if not fs.exists(dir) then
  22.     fs.makeDir(dir)
  23.   end
  24.   local f = fs.open(path, "w")
  25.   f.write(h.readAll())
  26.   f.close()
  27.   print("Done.")
  28. end
  29. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement