Jump to content




filehost/ftp server?


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

#1 cheekycharlie101

  • Members
  • 231 posts

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

#2 Doyle3694

  • Members
  • 815 posts

Posted 06 December 2012 - 05:38 AM

Are you trying to edit files irl or on another cc computer?

#3 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

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.

#4 cheekycharlie101

  • Members
  • 231 posts

Posted 06 December 2012 - 05:57 AM

View PostDoyle3694, on 06 December 2012 - 05:38 AM, said:

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

#5 cheekycharlie101

  • Members
  • 231 posts

Posted 06 December 2012 - 06:00 AM

View PostHuman, on 06 December 2012 - 05:44 AM, said:

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?

#6 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 06 December 2012 - 06:15 AM

Spoiler
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.

#7 cheekycharlie101

  • Members
  • 231 posts

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

#8 ChunLing

  • Members
  • 2,027 posts

Posted 06 December 2012 - 08:30 PM

You can just print it, if that's what you're wanting to do.

#9 ChaddJackson12

  • Members
  • 264 posts

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.

#10 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 07 December 2012 - 06:31 PM

View PostChaddJackson12, on 07 December 2012 - 03:13 PM, said:

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.

#11 cheekycharlie101

  • Members
  • 231 posts

Posted 07 December 2012 - 09:03 PM

View PostChaddJackson12, on 07 December 2012 - 03:13 PM, said:

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.

#12 ChaddJackson12

  • Members
  • 264 posts

Posted 08 December 2012 - 12:16 PM

View Postcheekycharlie101, on 07 December 2012 - 09:03 PM, said:

View PostChaddJackson12, on 07 December 2012 - 03:13 PM, said:

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.

#13 snoble2022

  • Members
  • 100 posts
  • LocationSomewhere near the local computer store?

Posted 09 December 2012 - 08:45 PM

Yeah, i don't know exactly how but try http.post





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users