Advertisement
ElijahCrafter

Untitled

Mar 19th, 2024 (edited)
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. -- Define the target computer's ID here
  2. local targetComputerID = 1 -- Change this to the ID of your target computer
  3.  
  4. -- Function to open the modem on the source computer
  5. local function openModem()
  6.     local modemSide
  7.     for _, side in ipairs(rs.getSides()) do
  8.         if peripheral.getType(side) == "modem" then
  9.             modemSide = side
  10.             break
  11.         end
  12.     end
  13.  
  14.     if modemSide and not rednet.isOpen(modemSide) then
  15.         rednet.open(modemSide)
  16.     end
  17. end
  18.  
  19. -- Function to send a file from the source computer to the target computer
  20. local function sendFile(sourcePath, targetPath)
  21.     local file = fs.open(sourcePath, "r")
  22.     if file then
  23.         local contents = file.readAll()
  24.         file.close()
  25.         rednet.send(targetComputerID, {targetPath, contents}, "fileTransfer")
  26.     else
  27.     end
  28. end
  29.  
  30. -- Main function to send non-default programs to the target computer
  31. local function sendNonDefaultPrograms()
  32.     openModem()
  33.     local files = fs.list("")
  34.     for _, file in ipairs(files) do
  35.         if fs.isDir(file) == false and file ~= "startup" then
  36.             sendFile(file, file)
  37.         end
  38.     end
  39. end
  40.  
  41. -- Main program execution
  42. sendNonDefaultPrograms()
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement