computercraft/send_file.lua
2021-01-09 03:30:47 +01:00

33 lines
619 B
Lua

local sides = peripheral.getNames()
for i = 1, #sides do
if peripheral.getType(sides[i]) == "modem" then
modemSide = sides[i]
break
end
end
rednet.open(modemSide)
term.write("Path: ")
path = tostring(read())
local file = fs.open(path, "r")
content = file.readAll()
data = textutils.serialize(content)
term.write("Receiver id: ")
id = tonumber(read())
print("Initialize receiver please!")
print("Press 's' to send")
local event, c = os.pullEvent("char")
if c == "s" then
print("Sending...")
print(id)
rednet.send(id, data)
else
print("Aborted.")
end
rednet.close(modemSide)