Advertisement
DYankee

file Server

Oct 5th, 2022 (edited)
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. --start up
  2.  
  3. peripheral.find("modem", rednet.open)
  4. rednet.host("fileServer","fileServer1ed ")
  5.  
  6. if fs.isDir("os/programs") == false then
  7.     fs.makeDir"os/programs"
  8. end
  9.  
  10. local programList = fs.list("os/programs")
  11.  
  12.  
  13. while true do
  14.     local id, msg = rednet.receive("fileServer")
  15.     if msg[1] == "filelist" then
  16.         rednet.send(id, programList)
  17.         print("computer-"..id..": asked for filelist")
  18.     elseif msg[1] == "request" then
  19.         print("computer - "..id..": asked for file > "..msg[2])
  20.         local file = fs.open("os/programs/"..msg[2], "r")
  21.         local contents = file.readAll()
  22.         rednet.send(id, contents)
  23.         file.close()
  24.     else
  25.         rednet.send(id,"invalid request")
  26.     end
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement