local component = require("component") local event = require("event") local fs = require("filesystem") local io = require("io") local shell = require("shell") local m = component.proxy(component.list("modem")()) local os = require("os") arg = {...} function listen(m) while true do local _, _, from, port, _, msg = event.pull("modem_message") print(e, from, port, msg, type(msg)) local pos = msg:find("%s") local sub = msg:sub(pos+1) --Get command and file name local command = msg:sub(0, pos-1) pos = sub:find("%s") local file = "" if pos ~= nil then file = sub:sub(0, pos-1) else file = sub end os.sleep(.1) if command == "ls" then m.send(from, port, fs.list(file)) elseif command == "cd" then m.send(from, port, shell.setPath(file)) elseif command == "pull" then f = fs.open(file, "r") if f == nil then m.send(from, port, "ERROR") else m.send(from, port, "OK") os.sleep(.1) m.send(from, port, f.readAll()) f:close() end elseif command == "put" then f = io.open(file, "w") if pos == nil then m.send(from, port, "ERROR") else f:write(sub:sub(pos+1)) f:close() m.send(from, port, "OK") end else m.send(from, port, "ERROR") end end end local port = 21 if arg[1] ~= nil then port = tonumber(arg[1]) end if m == nil then print("No modems found") return end if not m.isOpen(21) then m.open(21) end listen(m)