Sorry, I always forget the open call :unsure:/>/>
Try with this:
sendfile:
local tArgs = { ... }
if #tArgs ~= 2 then
print("Usage: sendfile <filename> <id>")
return
end
local function OpenModem()
for _, s in ipairs(rs.getSides()) do
if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
rednet.open(s)
return true
end
end
return false, "No modem found."
end
local ok, err = OpenModem()
if not ok then
print(err)
return
end
local file = io.open(tArgs[1], "r")
if file then
local s = file:read("*a")
local id = tonumber(tArgs[2])
if id then
rednet.send(id, s)
print("File ", tArgs[1], " sent to ", id)
else
print("ID should be number")
end
else
print("No such file "..tArgs[1])
end
getfile:
local tArgs = { ... }
local timer
if #tArgs < 1 or #tArgs > 2 then
print("Usage: getfile <filename> <timeout>")
return
end
if #tArgs == 2 then
local timeout = tonumber(tArgs[1])
if timeout then
timer = os.startTimer(timeout)
end
end
local function OpenModem()
for _, s in ipairs(rs.getSides()) do
if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
rednet.open(s)
return true
end
end
return false, "No modem found."
end
local ok, err = OpenModem()
if not ok then
print(err)
return
end
while true do
local evt, param, msg = os.pullEvent()
if evt == "rednet_message" then
local file = io.open(tArgs[1], "w")
if file then
file:write(msg)
file:close()
print("File received and saved as ", tArgs[1])
else
print("Error opening file "..tArgs[1])
end
break
elseif evt == "timer" and param == timer then
break
end
end
I tested it, it works with modems (autodetects on wich side the modem is), if you need to use it with bundled cables tell me and i'll modify it.