Advertisement
DOGGYWOOF

Recovery reciever

Feb 27th, 2024
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. function receiveRecoveryFiles()
  2. local modemSide = "top" -- Replace with the side where your modem is connected
  3. local computerID = os.getComputerID()
  4.  
  5. -- Open the modem
  6. rednet.open(modemSide)
  7.  
  8. print("Waiting for recovery files...")
  9. while true do
  10. local senderID, message, distance = rednet.receive()
  11.  
  12. if senderID == computerID and type(message) == "table" and message.action == "copyFiles" then
  13. local sourcePath = message.source
  14. local destinationPath = message.destination
  15.  
  16. print("Copying files from '" .. sourcePath .. "' to '" .. destinationPath .. "'...")
  17.  
  18. local success = copyFiles(sourcePath, destinationPath)
  19.  
  20. if success then
  21. rednet.send(senderID, "success")
  22. print("Files copied successfully.")
  23. else
  24. rednet.send(senderID, "failure")
  25. print("Failed to copy files.")
  26. end
  27. break -- Break the loop after processing the message
  28. end
  29. end
  30.  
  31. -- Close the modem
  32. rednet.close(modemSide)
  33. end
  34.  
  35. function copyFiles(sourcePath, destinationPath)
  36. -- Implement the logic to copy files here
  37. -- You can use the fs API functions to copy files
  38.  
  39. local success = true
  40.  
  41. -- Example: Copy all files from sourcePath to destinationPath
  42. local files = fs.list(sourcePath)
  43. for _, file in ipairs(files) do
  44. local sourceFile = fs.combine(sourcePath, file)
  45. local destinationFile = fs.combine(destinationPath, file)
  46.  
  47. if fs.exists(sourceFile) and not fs.exists(destinationFile) then
  48. success = fs.copy(sourceFile, destinationFile)
  49. if not success then
  50. break -- Break the loop if any copy operation fails
  51. end
  52. end
  53. end
  54.  
  55. return success
  56. end
  57.  
  58. -- Run the function to receive recovery files
  59. receiveRecoveryFiles()
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement