Advertisement
DOGGYWOOF

Doggy OS install client

Jul 27th, 2024
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. -- Client Code
  2. local modem = peripheral.wrap("left") -- Adjust as necessary to match your modem's side
  3. modem.open(123) -- Open a channel for communication
  4.  
  5. local TARGET_ID = 123 -- Replace with the actual computer ID of the source computer
  6.  
  7. -- Function to send a request to the specific computer ID
  8. local function requestDisk()
  9. rednet.open("left") -- Adjust as necessary to match your modem's side
  10. rednet.send(TARGET_ID, "GET_DISK", "disk")
  11. end
  12.  
  13. -- Function to receive the directory from the source computer
  14. local function receiveDirectory(path)
  15. while true do
  16. local id, message, protocol = rednet.receive("disk")
  17. if protocol == "disk" then
  18. if message.type == "end" then
  19. print("Download complete.")
  20. return
  21. elseif message.type == "dir" then
  22. local newPath = path .. "/" .. message.name
  23. fs.makeDir(newPath)
  24. receiveDirectory(newPath)
  25. elseif message.type == "file" then
  26. local filePath = path .. "/" .. message.name
  27. local file = fs.open(filePath, "w")
  28. file.write(message.content)
  29. file.close()
  30. end
  31. end
  32. end
  33. end
  34.  
  35. requestDisk()
  36. receiveDirectory("/disk/")
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement