Jump to content




Attempt to index ? a nil value


  • You cannot reply to this topic
3 replies to this topic

#1 Creeper9207

  • Members
  • 211 posts

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 value

Edited by Creeper9207, 21 February 2015 - 08:09 PM.


#2 Anavrins

  • Members
  • 775 posts

Posted 21 February 2015 - 08:17 PM

It means that "z = fs.open(sFile, "r")" did not return anything, either because the file doesn't exist, or your gsub pattern isn't doing what you think it's doing.

#3 Creeper9207

  • Members
  • 211 posts

Posted 21 February 2015 - 08:20 PM

solved, but now in the client fOutput = fs.open(msgp, "w")
fOutput.write(fdata) is nil

#4 Anavrins

  • Members
  • 775 posts

Posted 21 February 2015 - 09:18 PM

Can't help you if you don't post your client code.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users