Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protocol = "lddftp"
- protocolping = "lddping"
- tArg = {...}
- command = tArg[1]
- argument1 = tArg[2]
- periphs = peripheral.getNames()
- for a = 1, #periphs do
- if peripheral.getType(periphs[a]) == "modem" then
- rednet.open(periphs[a])
- end
- end
- if command == "send" then
- if argument1 ~= nil then
- file = fs.open(argument1, "r")
- stuff = {}
- table.insert(stuff, argument1)
- table.insert(stuff, {file.readAll()})
- file.close()
- if argument2 == nil then
- rednet.broadcast(stuff, protocol)
- else
- rednet.send(stuff, protocol)
- end
- else
- error("expected filename, got nil")
- end
- elseif command == "receive" then
- if argument1 == nil then
- print("Waiting...")
- elseif tonumber(argument1) == nil then
- error("expected number for id")
- else
- print("Waiting for " .. argument1)
- end
- while true do
- id, msg = rednet.receive("protocol")
- if msg ~= nil then
- if type(msg) == "table" then
- fileName = msg[1]
- print("Got '" .. fileName .. "' from " .. id)
- file = fs.open(fileName, "w")
- file.writeLine(stuff[2])
- file.close()
- return
- end
- end
- end
- else
- error("incorrect command")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement