Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function receiveRecoveryFiles()
- local modemSide = "top" -- Replace with the side where your modem is connected
- local computerID = os.getComputerID()
- -- Open the modem
- rednet.open(modemSide)
- print("Waiting for recovery files...")
- while true do
- local senderID, message, distance = rednet.receive()
- if senderID == computerID and type(message) == "table" and message.action == "copyFiles" then
- local sourcePath = message.source
- local destinationPath = message.destination
- print("Copying files from '" .. sourcePath .. "' to '" .. destinationPath .. "'...")
- local success = copyFiles(sourcePath, destinationPath)
- if success then
- rednet.send(senderID, "success")
- print("Files copied successfully.")
- else
- rednet.send(senderID, "failure")
- print("Failed to copy files.")
- end
- break -- Break the loop after processing the message
- end
- end
- -- Close the modem
- rednet.close(modemSide)
- end
- function copyFiles(sourcePath, destinationPath)
- -- Implement the logic to copy files here
- -- You can use the fs API functions to copy files
- local success = true
- -- Example: Copy all files from sourcePath to destinationPath
- local files = fs.list(sourcePath)
- for _, file in ipairs(files) do
- local sourceFile = fs.combine(sourcePath, file)
- local destinationFile = fs.combine(destinationPath, file)
- if fs.exists(sourceFile) and not fs.exists(destinationFile) then
- success = fs.copy(sourceFile, destinationFile)
- if not success then
- break -- Break the loop if any copy operation fails
- end
- end
- end
- return success
- end
- -- Run the function to receive recovery files
- receiveRecoveryFiles()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement