Advertisement
mouse03f

FilesOnline v1

Jun 8th, 2021 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. function online()
  2.     term.clear()
  3.     term.setCursorPos(1,1)
  4.      
  5.     rednet.open("right")
  6.     function receive()
  7.         while(true) do
  8.         local id, msg = rednet.receive()
  9.         if msg == "ctlg" then
  10.             local text = fs.list()
  11.             rednet.broadcast(text)
  12.         end
  13.         if msg == "svths"
  14.         then
  15.             local id, name = rednet.receive()
  16.             local id, text = rednet.receive()
  17.             local file = fs.open(name, "w")
  18.             file.write(text)
  19.             file.close()
  20.             print("you just received a new file called: ") print(name)
  21.         else
  22.             print(msg)
  23.         end
  24.  
  25.         end
  26.     end
  27.      
  28.     function send()
  29.         while(true) do
  30.         local msg = io.read()
  31.  
  32.         if msg == "send"
  33.         then
  34.             print("please enter the name of the file you'd like to send:")
  35.             local file = io.read()
  36.             local file = fs.open(file, "r")
  37.             if file then
  38.                 local text = file.readAll()
  39.                 file.close()
  40.  
  41.                 print("Give the file a name for the reciever")
  42.                 local name = io.read()
  43.                 rednet.broadcast("svths")
  44.                 sleep(0.1)
  45.                 rednet.broadcast(name)
  46.                 sleep(0.1)
  47.                 rednet.broadcast(text)
  48.                 print("The file was transferred succesfully =)")
  49.             end
  50.             if  msg == "grab" then
  51.                 print("please enter the name of the file you'd like to send:")
  52.                 local file = io.read()
  53.                 local file = fs.open(file, "r")
  54.                 if file then
  55.                     local text = file.readAll()
  56.                     file.close()
  57.      
  58.                     print("Give the file a name for the reciever")
  59.                     local name = io.read()
  60.                     rednet.broadcast("svths")
  61.                     sleep(0.1)
  62.                     rednet.broadcast(name)
  63.                     sleep(0.1)
  64.                     rednet.broadcast(text)
  65.                     print("The file was transferred succesfully =)")
  66.             else
  67.                 print("File doesn't exist.")
  68.             end        
  69.         else
  70.         rednet.broadcast("RMS: "..msg)
  71.         end
  72.     end
  73. end
  74. parallel.waitForAll(receive,send)
  75. end
  76. online()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement