thanks -Cheeky
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
filehost/ftp server?
Started by cheekycharlie101, 06 December 2012 - 04:34 AMPosted 06 December 2012 - 05:34 AM
so, my question is. is it possible to create a filehost/ftp server in computercraft. if it is, could someone help me out by telling me how to send programs and receive them. would you have to convert the program into a string the convert it back into a file after its sent? im not really sure so does anyone have any advice for me. note i will go search around the wiki and stuff to see if this has been done before and if so how ete ete.
thanks -Cheeky
thanks -Cheeky
Posted 06 December 2012 - 05:38 AM
Are you trying to edit files irl or on another cc computer?
Posted 06 December 2012 - 05:44 AM
When you read a script it is a string. So all you have to do is send it to the computer.
Client:
Server:
Client:
local args = {...}
for k,v in pairs(rs.getSides()) do
rednet.open(v)
end
if #args ~= 2 then
error("Usage: "..shell.getRunningProgram.." <path> <send ID>")
end
if not fs.exists(args[1]) then
error("File does not exist.")
end
f = fs.open(args[1], "r")
local file = f.readAll()
f.close()
rednet.send(args[2], file)
Server:
local args = {...}
if #args ~= 2 then
error("Usage: "..shell.getRunningProgram.." <save file> <ID>")
endfor k,v in pairs(rs.getSides()) do
rednet.open(v)
end
while true do
id, msg = rednet.receive()
if id == args[2] then
f = fs.open(args[1], "w")
f.write(msg)
f.close()
break
end
end
This is all basic and you should get the basic idea of it.Posted 06 December 2012 - 05:57 AM
send files from one CC computer to another CC computer acting as a server. then the server can send them back to you or another client computerAre you trying to edit files irl or on another cc computer?
Posted 06 December 2012 - 06:00 AM
thanks. also can you help me with receiving a list.When you read a script it is a string. So all you have to do is send it to the computer.
Client:local args = {...} for k,v in pairs(rs.getSides()) do rednet.open(v) end if #args ~= 2 then error("Usage: "..shell.getRunningProgram.." <path> <send ID>") end if not fs.exists(args[1]) then error("File does not exist.") end f = fs.open(args[1], "r") local file = f.readAll() f.close() rednet.send(args[2], file)
Server:This is all basic and you should get the basic idea of it.local args = {...} if #args ~= 2 then error("Usage: "..shell.getRunningProgram.." <save file> <ID>") endfor k,v in pairs(rs.getSides()) do rednet.open(v) end while true do id, msg = rednet.receive() if id == args[2] then f = fs.open(args[1], "w") f.write(msg) f.close() break end end
i did this code on my computer:
for i,v in pairs(fs.list("/") do
print(v)
end
and it showed all the directories and files as it should. but when i tried sending "v" over rednet when it was received it would only print the first program. any idea why this is happening?Posted 06 December 2012 - 06:15 AM
Spoiler
thanks. also can you help me with receiving a list.When you read a script it is a string. So all you have to do is send it to the computer.
Client:local args = {...} for k,v in pairs(rs.getSides()) do rednet.open(v) end if #args ~= 2 then error("Usage: "..shell.getRunningProgram.." <path> <send ID>") end if not fs.exists(args[1]) then error("File does not exist.") end f = fs.open(args[1], "r") local file = f.readAll() f.close() rednet.send(args[2], file)
Server:This is all basic and you should get the basic idea of it.local args = {...} if #args ~= 2 then error("Usage: "..shell.getRunningProgram.." <save file> <ID>") endfor k,v in pairs(rs.getSides()) do rednet.open(v) end while true do id, msg = rednet.receive() if id == args[2] then f = fs.open(args[1], "w") f.write(msg) f.close() break end end
i did this code on my computer:and it showed all the directories and files as it should. but when i tried sending "v" over rednet when it was received it would only print the first program. any idea why this is happening?for i,v in pairs(fs.list("/") do print(v) end
--To make a table a string:
local test = textutils.serialize(fs.list("/"))
--To make a string into a table:
textutils.unserialize(test)
I hope that helps.Posted 06 December 2012 - 08:42 AM
if the server turns it into a string couldn't you just print the string at the other end? or would i need to turn it back into a table
Posted 06 December 2012 - 08:30 PM
You can just print it, if that's what you're wanting to do.
Posted 07 December 2012 - 03:13 PM
While we're talking about server stuff… Is it possibly to have an FTP host/HTTP storage host? So you could have literally global computercraft files? Like dropbox? I think that'd be incredibly useful, for many people.
Posted 07 December 2012 - 06:31 PM
While we're talking about server stuff… Is it possibly to have an FTP host/HTTP storage host? So you could have literally global computercraft files? Like dropbox? I think that'd be incredibly useful, for many people.
Derp, you answered your own question. Use Dropbox.
Posted 07 December 2012 - 09:03 PM
just use pastebin and the HTTP api.While we're talking about server stuff… Is it possibly to have an FTP host/HTTP storage host? So you could have literally global computercraft files? Like dropbox? I think that'd be incredibly useful, for many people.
Posted 08 December 2012 - 12:16 PM
Not talking about set code. I'm talking about basically hosting files, and folders that can be edited. Say, an online user system? So the users could send each other messages through the internet, rather than just on a server.just use pastebin and the HTTP api.While we're talking about server stuff… Is it possibly to have an FTP host/HTTP storage host? So you could have literally global computercraft files? Like dropbox? I think that'd be incredibly useful, for many people.
Posted 09 December 2012 - 08:45 PM
Yeah, i don't know exactly how but try http.post