Advertisement
DOGGYWOOF

server - netork

Jan 21st, 2024 (edited)
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. -- Server Program
  2.  
  3. local modemSide = "top" -- Adjust the side where your modem is connected
  4. local serverID = "exampleServer" -- Set a unique server ID
  5.  
  6. rednet.open(modemSide)
  7.  
  8. while true do
  9. local _, message = rednet.receive(serverID)
  10.  
  11. if message == "list_files" then
  12. local files = fs.list("/network")
  13. rednet.send(_, textutils.serialize(files))
  14.  
  15. elseif message:match("^delete_file:(.+)$") then
  16. local _, fileName = message:match("^delete_file:(.+)$")
  17. fs.delete("/network/" .. fileName)
  18. rednet.send(_, "File deleted.")
  19.  
  20. elseif message:match("^move_file:(.+),(.+)$") then
  21. local _, source, destination = message:match("^move_file:(.+),(.+)$")
  22. fs.move("/network/" .. source, "/network/" .. destination)
  23. rednet.send(_, "File moved.")
  24.  
  25. elseif message:match("^copy_file:(.+),(.+)$") then
  26. local _, source, destination = message:match("^copy_file:(.+),(.+)$")
  27. fs.copy("/network/" .. source, "/network/" .. destination)
  28. rednet.send(_, "File copied.")
  29.  
  30. elseif message:match("^edit_file:(.+)$") then
  31. local _, fileName = message:match("^edit_file:(.+)$")
  32. shell.run("edit /network/" .. fileName)
  33. rednet.send(_, "File edited.")
  34. end
  35. end
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement