This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Backplague's profile picture

[Lua][Question] Is it possible to send whole files to another computer?

Started by Backplague, 09 April 2012 - 06:20 PM
Backplague #1
Posted 09 April 2012 - 08:20 PM
Since i want to send a program from a computer to another computer without sending each line of the program individually over Rednet.
MysticT #2
Posted 09 April 2012 - 09:04 PM
You can use readAll() to read the text from the file and then send it:

function sendFile(id, path)
  local file = fs.open(path, "r")
  if file then
    local sText = file.readAll()
    file.close()
    rednet.send(id, sText)
  end
end
Wolvan #3
Posted 09 April 2012 - 10:54 PM
and then you have to write it on the receiving computer again like this:

function receiveWrite(path)
local file = fs.open(path, "w")
if file then
file.close()
print("File exists. Writing to "..path.."2")
file = fs.open(path.."2", "w")
end
id, filetext = rednet.receive()
file:write(filetext)
file.close()
end
Backplague #4
Posted 10 April 2012 - 06:08 AM
Thanks!