Posted 21 February 2015 - 08:06 PM
--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, ":", "")
print(j)
xFile = xFile:gsub(":" .. j .. ":", "")
z = fs.open(xFile, "r")
y = z.readAll() --ERRORING LINE
z.close()
rednet.broadcast(y .. ":fileincoming:<" .. xFile .. ">", "incoming")
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
while true do
senderID, msg, dis, protocol = rednet.receive("outgoing")
msgp = string.match(msg, "(%b<>)")
if msgp == "<dir>" then
msg = msg:gsub(msgp, "")
print("CMD $DIR " .. msg)
getlist(msg)
elseif msgp == "<Trans>" then
msg = msg:gsub(msgp, "")
print("CMD $TRANS " .. msg)
transferFile(msg)
elseif msgp == "<Rec>" then
print("CMD $TRANS " .. msg)
recieveFile(msg)
end
end
line 38 errors "attempt to index ? a nil valueEdited on 21 February 2015 - 07:09 PM