Z1maV1

sendFiles

May 15th, 2022 (edited)
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. rednet.open("top")
  2.  
  3. term.clear()
  4. term.setCursorPos(1,1)
  5.  
  6. write("Write computer id (if not, write -1): ")
  7. id = tonumber(read())
  8.  
  9. write("Write path to file: ")
  10. sendF = read()
  11.  
  12. write("Write protocol: ")
  13. protocol = read()
  14.  
  15. if id == -1 then
  16.     if fs.exists(sendF) then
  17.         textutils.slowPrint("Sending File '"..sendF.."'!")
  18.         rednet.broadcast("RECEIVE", protocol)
  19.         rednet.broadcast(sendF, protocol)
  20.         file = fs.open(sendF, "r")
  21.         rednet.broadcast(file.readAll(), protocol)
  22.         file.close()
  23.     else
  24.         print(sendF.." does not exist")
  25.         return
  26.     end
  27. else
  28.     if fs.exists(sendF) then
  29.         textutils.slowPrint("Sending file '"..sendF.."' to "..id)
  30.         F = fs.open(sendF, "r")
  31.         rednet.send(id, "RECEIVE", protocol)
  32.         rednet.send(id, sendF, protocol)
  33.         rednet.send(id, F.readAll(), protocol)
  34.         F.close()
  35.     else
  36.         print(sendF.." does not exist!")
  37.         return
  38.     end
  39. end
  40.  
Advertisement
Add Comment
Please, Sign In to add comment