Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- op = args[1]
- server_id = tonumber(args[2])
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- if op == "send" or op == "get" then
- file = args[3]
- end
- local present = false
- for _, side in pairs(rs.getSides()) do
- if peripheral.getType(side) == "modem" then
- present = true
- rednet.open(side)
- end
- end
- if op == "list" then
- rednet.send(server_id, "list:all", "FTP")
- id, list = rednet.receive("FTP")
- files = split(list, ":")
- for i=1,tablelength(files) do
- print(files[i])
- end
- elseif op == "get" then
- rednet.send(server_id, "get:" .. file, "FTP")
- id, file_data = rednet.receive("FTP")
- if file_data == "1" then
- printError("file does not exsist on server")
- return
- end
- file_table = split(file_data, ":*:")
- file_name = file_table[1]
- file_content = file_table[2]
- if fs.exists(file_name) == true then
- print("file alredy exsists")
- else
- file = fs.open(file_name, "w")
- file.write(file_content)
- file.close()
- end
- elseif op == "send" then
- print("wip")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement