Posted 17 August 2012 - 06:10 AM
Not sure if the problem is with io or my fs table.
I am writing a basic program to transfer all of the files from one computer to another. This will eventually include whatever is on the disk, but for now, it just does the root directory.
At least is should.
I am getting an "attempt to index? (a nil value)" at line 9 of this code (the client sending the files):
also, here is the server (which receives the files):
The client is run by "<program name> <id of server>"
The server is run by "<program name> <id of client>"
Any and all help is appreciated, weather it is about my syntax, program etiquette, or anything else.
Lastly, please do not just post the answer for me. I picked up computercraft to expand my programming knowledge, not to be hand-fed.
I am here to learn, not to be told.
Thank you,
ZeroLRS
I am writing a basic program to transfer all of the files from one computer to another. This will eventually include whatever is on the disk, but for now, it just does the root directory.
At least is should.
I am getting an "attempt to index? (a nil value)" at line 9 of this code (the client sending the files):
args = {...}
rednet.open("top")
x = 1
FileList = fs.list("")
rednet.send(tonumber(args[1]), tostring(#FileList))
for _,fileName in ipairs(FileList) do
file = io.open(fileName, "r")
s = file:read("*a")
rednet.send(tonumber(args[1]), s)
file:close()
print("File ", x , " sent.")
end
rednet.close("top")
also, here is the server (which receives the files):
args = {...}
rednet.open("top")
print("Rednet opened on top")
sid1, number = rednet.receive()
sid2, file = rednet.receive()
print("Files receiving from ", sid1)
if tonumber(args[1]) == sid1 then
print("sid matched the argument")
for n = 1, number do
sid2, fileContent = rednet.receive()
file = io.open(tonumber(n), "w")
if file then
file:write(fileContent)
file:close()
print("File ", n, " of ", number, " received sucessfully!")
end
end
rednet.close("top")
print("Rednet Closed!")
end
The client is run by "<program name> <id of server>"
The server is run by "<program name> <id of client>"
Any and all help is appreciated, weather it is about my syntax, program etiquette, or anything else.
Lastly, please do not just post the answer for me. I picked up computercraft to expand my programming knowledge, not to be hand-fed.
I am here to learn, not to be told.
Thank you,
ZeroLRS