Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Client Code
- local modem = peripheral.wrap("left") -- Adjust as necessary to match your modem's side
- modem.open(123) -- Open a channel for communication
- local TARGET_ID = 123 -- Replace with the actual computer ID of the source computer
- -- Function to send a request to the specific computer ID
- local function requestDisk()
- rednet.open("left") -- Adjust as necessary to match your modem's side
- rednet.send(TARGET_ID, "GET_DISK", "disk")
- end
- -- Function to receive the directory from the source computer
- local function receiveDirectory(path)
- while true do
- local id, message, protocol = rednet.receive("disk")
- if protocol == "disk" then
- if message.type == "end" then
- print("Download complete.")
- return
- elseif message.type == "dir" then
- local newPath = path .. "/" .. message.name
- fs.makeDir(newPath)
- receiveDirectory(newPath)
- elseif message.type == "file" then
- local filePath = path .. "/" .. message.name
- local file = fs.open(filePath, "w")
- file.write(message.content)
- file.close()
- end
- end
- end
- end
- requestDisk()
- receiveDirectory("/disk/")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement