This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cheekycharlie101's profile picture

filehost/ftp server?

Started by cheekycharlie101, 06 December 2012 - 04:34 AM
cheekycharlie101 #1
Posted 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
Doyle3694 #2
Posted 06 December 2012 - 05:38 AM
Are you trying to edit files irl or on another cc computer?
Sammich Lord #3
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:

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.
cheekycharlie101 #4
Posted 06 December 2012 - 05:57 AM
Are you trying to edit files irl or on another cc computer?
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 computer
cheekycharlie101 #5
Posted 06 December 2012 - 06:00 AM
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:

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.
thanks. also can you help me with receiving a list.
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?
Sammich Lord #6
Posted 06 December 2012 - 06:15 AM
Spoiler
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:

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.
thanks. also can you help me with receiving a list.
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?
fs.list returns a table. So you have to serialize the table and un-serialize it on the other 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.
cheekycharlie101 #7
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
ChunLing #8
Posted 06 December 2012 - 08:30 PM
You can just print it, if that's what you're wanting to do.
ChaddJackson12 #9
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.
Dlcruz129 #10
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.
cheekycharlie101 #11
Posted 07 December 2012 - 09:03 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.
just use pastebin and the HTTP api.
ChaddJackson12 #12
Posted 08 December 2012 - 12:16 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.
just use pastebin and the HTTP api.
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.
snoble2022 #13
Posted 09 December 2012 - 08:45 PM
Yeah, i don't know exactly how but try http.post