Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tArgs = {...}
- local function printUsage()
- print("Usage: ")
- print(shell.getRunningProgram().." send <file> <id>")
- print(shell.getRunningProgram().." receive <id>")
- end
- local function receive()
- id, msg = rednet.receive(10)
- if msg == nil then
- error("Connection timed out.")
- else
- if id == tArgs[2] then
- local data = textutils.unserialize(msg)
- local handle = fs.open(data[1], "w")
- handle.write(data[2])
- handle.close()
- print("File saved as "..data[1])
- error()
- end
- end
- end
- local function send()
- local handle = fs.open(tArgs[2], "r")
- local handleData = handle.readAll()
- local data = {}
- table.insert(data, 1, tArgs[2])
- table.insert(data, 2, handleData)
- local msg = textutils.serialize(data)
- rednet.send(tonumber(tArgs[3]), msg)
- end
- local function openAll()
- for _,v in pairs(rs.getSides()) do
- if peripheral.isPresent(v) and peripheral.getType(v) == "modem" then
- rednet.open(v)
- end
- end
- end
- if #tArgs < 2 then
- printUsage()
- error()
- end
- openAll()
- if tArgs[1] == "send" then send() elseif tArgs[1] == "receive" then receive() end
Advertisement
Add Comment
Please, Sign In to add comment