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

Remote file viewer?

Started by lieudusty, 02 August 2012 - 02:20 AM
lieudusty #1
Posted 02 August 2012 - 04:20 AM
Hi everyone! :ph34r:/>/>

I'm making a file server and I need to make a remote file browser. I want to make this but I have no idea on how this would be done. Can somebody help please? Thanks!
Noodle #2
Posted 02 August 2012 - 04:58 AM
You could use the FS and Rednet apis to do this.
Or use the apache browser..
Zudo #3
Posted 29 September 2012 - 04:21 PM
Try using rednet to send the contents of the file but i just cant think of a way to edit it…
Pharap #4
Posted 30 September 2012 - 03:27 AM
one computer stores all the files and sends them in a message when requested, when the other computer receives it, have it convert it into an actual file (essentially downloading it) and then do the reverse for uploading.
All you need to do is figure out a decent way of signifying whether you want to download or upload a file (either via a preliminary message or via a tag at the beginning of the message like XML does)
That's the theory sorted, obviously you'd need the rednet and fs APIs, and coroutines would help if you wanted many computers accessing the data at once.
Such things are beyond me at the moment though, I am too tired to think of such complicated things.
GopherAtl #5
Posted 30 September 2012 - 04:37 PM
I usually try to help without actually writing programs for people, but for some reason I felt like writing my own approach to this one. I took a shell-based approach on the client side, have programs fget, fput, and flist that download, upload, or list the files on a server, plus setshare that sets the id of the computer running the main fileshare program. Specifically doesn't support subdirectories, instead putting or getting files only from a /shared directory. Doesn't do any authorizing either, just trusts requests from any computer.

to setup the server program:

pastebin get kyeT1W7t fileshare
then just run fileshare to start the server. Expects a modem on top, if you've got it elsewhere change line 2 to replace "top" with whatever side it's on.

For the client, I made a crude downloader script so you don't have to pastebin get 4 different programs:

pastebin get VKLPjcPE setup
setup
delete setup
when you run setup, you should see the messages as it runs pastebin 4 times to download fput, fget, flist, and setshare.

To use it…
Spoiler1) find out the id of the server - you can do this by running "id" on the server at the command prompt.
2) run fileshare on the server. It will run until stopped with ctrl-t, or until the computer is rebooted. All handled requests are logged to the screen and to a fileshare.log file.
3) on the client, run "setshare <id>", where <id> is the id of the server from step 1. this id will be saved to a hidden file called ".shareServer" so unless you're using multiple fileshare servers and need to switch between them, you only have to do this once.
4) Open the modem on the client! The programs assume it is open; if it's not, all commands except setshare will give a request timed out error.
5) just use the commands.

"flist" will list the files in the /shared directory on the server

"fput myfile" will send the file named "myfile" to the server. Note, any local path will be stripped, i.e., sending "/rom/programs/shell" will create a file "/shared/shell" on the server! Also, it will give an error if you attempt to overwrite an existing file.

"fget myfile" downloads the named file from the server. Path is stripped here as well; typing "fget bin/myfile" will download "/shared/myfile" but will store that locally as "bin/myfile."

That's… pretty much it. Not very sophisticated, not very secure, but pretty simple to use, and a good starting point you could improve on.

source code links if you want to just read the code…
fileshare - server program
client programs:
setshare
fput
flist
fget</id></id>