Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local s = io.open("serverID", r)
- local server = s:read()
- server = tonumber(server)
- s:close()
- function upload(path)
- if not fs.exists(path) then
- print("ERROR: File " .. path .. " does not exist!")
- return
- end
- name = os.getComputerLabel()
- if name then
- path2 = name .. "/" .. path
- end
- path2 = path2 or path
- rednet.send(server, "ul." .. path2)
- os.startTimer(1)
- type, ignore, msg = os.pullEvent()
- file = io.open(path, "r")
- fileBody = file:read("*a")
- file:close()
- if type == "rednet_message" then
- if msg:find("Overwrite?") then
- write(msg)
- overwrite = read()
- overwrite:lower()
- rednet.send(server, overwrite)
- if overwrite ~= "y" then
- print("Transfer Aborted.")
- return
- end
- end
- end
- sleep(0.2)
- rednet.send(server, fileBody)
- os.startTimer(4)
- type, ignore, msg = os.pullEvent()
- if type == "rednet_message" then
- if msg == "finished" then
- print("Transfer completed successfully.")
- return
- end
- end
- print("Errors occured during upload. Please try again.")
- end
- function download(path)
- name = os.getComputerLabel()
- if name then
- path2 = name .. "/" .. path
- end
- path2 = path2 or path
- rednet.send(server, "dl." .. path2)
- ignore, msg = rednet.receive(1)
- if msg:sub(1, 6) == "ERROR:" then
- print(msg)
- return
- end
- if fs.exists(path) then
- print("File exists. Overwrite? (y/n): ")
- overwrite = read()
- overwrite:lower()
- rednet.send(server, overwrite)
- if overwrite ~= "y" then
- print("Transfer Aborted.")
- return
- end
- end
- file = io.open(path, "w")
- file:write(msg)
- file:close()
- print("Transfer completed successfully.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement