Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creeper9207 Code: ftp server--
- local tArgs = { ... }
- rednet.open("back")
- function getlist(tdir)
- -- Get all the files in the directory
- local sDir = shell.dir()
- if tdir ~= nil then
- sDir = shell.resolve( tdir )
- end
- -- Sort into dirs/files, and calculate column count
- local tAll = fs.list( sDir )
- local tFiles = {}
- local tDirs = {}
- for n, sItem in pairs( tAll ) do
- if string.sub( sItem, 1, 1 ) ~= "." then
- local sPath = fs.combine( sDir, sItem )
- if fs.isDir( sPath ) then
- table.insert( tDirs, sItem )
- else
- table.insert( tFiles, sItem )
- end
- end
- end
- table.sort( tDirs )
- table.sort( tFiles )
- rednet.broadcast("dirs: " .. textutils.serialize(tDirs) .. "files: " .. textutils.serialize(tFiles) .. ":text", "incoming")
- end
- function transferFile(xFile)
- j = string.match(xFile, "(%b::)")
- j = string.gsub(j, ":", "")
- xFile = xFile:gsub(":" .. j .. ":", "")
- if fs.exists(j) then
- z = fs.open(j, "r")
- y = z.readAll()
- z.close()
- rednet.broadcast(y .. ":fileincoming:<" .. j .. ">", "incoming")
- else
- rednet.broadcast("File does not exist:text")
- end
- end
- function recieveFile(mFile)
- g = string.match(mFile, "(%b<>)")
- f = string.match(mFile, "(%b::)")
- f = f:gsub(":", "")
- uFile = mFile:gsub(":" .. f .. ":", "")
- uFile = uFile:gsub("<Rec>", "")
- ow = fs.open(f, "w")
- ow.write(uFile)
- ow.flush()
- ow.close()
- rednet.broadcast("Success:text", "incoming")
- end
- if tArgs[1] then
- while true do
- senderID, msg, dis, protocol = rednet.receive("outgoing")
- if string.match(msg, "<") then
- msgp = string.match(msg, "(%b<>)")
- end
- passwd = string.match(msg, "(%b??)")
- msg = msg:gsub("?" .. passwd .. "?", "")
- passwd = string.gsub(passwd, "?", "")
- function verify()
- if passwd == tArgs[1] then
- else
- rednet.broadcast("Login Incorrect:text", "incoming")
- verify()
- end
- end
- verify()
- function commandrun()
- a = shell.run(msg)
- rednet.broadcast(tostring(a), "incoming")
- print("CMD $EXEC " .. msg)
- end
- commandr = 0
- if msg:match("cmd") then
- msg = msg:gsub("cmd ", "")
- commandrun()
- commandr = 1
- end
- if commandr == 0 then
- if msgp == "<dir>" then
- msg = msg:gsub(msgp, "")
- print("CMD $DIR " .. msg)
- getlist(msg)
- elseif msgp == "<Trans>" then
- msg = msg:gsub(msgp, "")
- print("CMD $GET " .. msg)
- transferFile(msg)
- elseif msgp == "<Rec>" then
- print("CMD $SEND " .. msg)
- recieveFile(msg)
- else
- end
- end
- end
- else
- print("usage: ftpserver <password>")
- end
Advertisement
Add Comment
Please, Sign In to add comment