Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- json = require "json"
- local ws, err = http.websocket("ws://localhost:8082")
- if err then
- print(err)
- elseif ws then
- print("[TURTLE] > Connected")
- print("Which file would you like to request?")
- local file = read()
- print("[TURTLE] > Requesting files...")
- local sendMsg = {
- type = "requestFile",
- file = file
- }
- ws.send(json.encode(sendMsg))
- local message = ws.receive()
- local fileCont = json.decode(message)
- if fileCont.type == "file" then
- fileCont = fileCont.file
- local newFile = fs.open(file, "w")
- newFile.write(fileCont)
- newFile.close()
- print("[TURTLE] > Succesfully downloaded "..file)
- elseif fileCont.type == "error" then
- print("[TURTLE] > Error: "..fileCont.error)
- end
- end
- ws.close()
Add Comment
Please, Sign In to add comment