Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function send(ID, path)
- if not fs.exists(path) then
- rednet.send(ID, "ERROR: File does not exist!")
- return
- end
- file = io.open(path, "r")
- print(path)
- fileBody = file:read("*a")
- file:close()
- rednet.send(ID, fileBody)
- end
- function receive(ID, path)
- if fs.exists(path) then
- count = 0
- while count < 10 do
- rednet.send(ID, "File exists on server. Overwrite? (y/n): ")
- ID2, msg = rednet.receive(1)
- if ID2 and ID ~= ID2 then
- rednet.send(ID2, "Server is busy. Try again in a moment.")
- elseif ID == ID2 and msg ~= "y" then
- return
- elseif ID == ID2 and msg == "y" then
- count = 20
- end
- if count == 10 then
- return
- end
- end
- end
- for count = 0, 10 do
- ID3, fBody = rednet.receive(1)
- if ID3 and ID3 ~= ID then
- rednet.send(ID3, "Server is busy. Try again in a moment.")
- end
- if ID3 == ID then
- file = io.open(path, "w")
- file:write(fBody)
- file:close()
- rednet.send(ID, "finished")
- return
- end
- end
- end
- rednet.open("right")
- while true do
- ID, msg = rednet.receive()
- if msg:sub(1, 2) == "dl" then
- send(ID, msg:sub(4))
- elseif msg:sub(1, 2) == "ul" then
- receive(ID, msg:sub(4))
- else
- rednet.send(ID, "ERROR: Invalid Command!")
- print("Invalid command!")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement