Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- wget substitute for ComputerCraft 1.7.10
- local tArgs = {...}
- if #tArgs < 2 then
- print("Usage: wget <url> <filename>")
- return
- end
- if not http then
- printError("wget requires http API")
- printError("Set http_enable to true in ComputerCraft.cfg")
- return
- end
- local url = tArgs[1]
- local filename = tArgs[2]
- local path = shell.resolve(filename)
- if fs.exists(path) then
- print("File already exists")
- return
- end
- write("Connecting to "..url.." ... ")
- local response = http.get(url)
- if not response then
- print("Failed.")
- return
- end
- print("Success.")
- local contents = response.readAll()
- response.close()
- local file = fs.open(path, "w")
- file.write(contents)
- file.close()
- print("Downloaded as "..filename)
Advertisement
Add Comment
Please, Sign In to add comment