Remote File Handling

M

Michael Maloney

Trying to use the File and Dir classes on remote directories with no
luck whatsoever. Here's what I want to do:

1. Put a bunch of files into a folder on an FTP server. This could be
anywhere.

2. SSH/SFTP/FTP/whatever into that folder (none of these have worked for
me thus far).

3. Use the Ruby File and Dir classes to operate on these files.

The main problem seems to be that if you use any of the Net:: stuff from
the standard library, you can do some stuff with the related File and
Dir utilities, but you're not actually working with the files themselves
as you would in the local environment.

Is there a way to access files directly on remote servers the way you
can in the local environment? Can I get into a remote server from my
local machine and do things like File.ctime(my_remote_file) ?

Thanks in advance.
 
B

Brian Candler

Michael said:
Is there a way to access files directly on remote servers the way you
can in the local environment? Can I get into a remote server from my
local machine and do things like File.ctime(my_remote_file) ?

Short answer: no.

Long answer: Ruby's Dir and File classes just sit on top of the
file/directory operations provided by the underlying operating system.
For example, Dir.pwd and Dir.chdir refer to the process's (local)
current working directory.

However, on some systems, if you install the right tools, you may be
able to 'mount' a remote FTP or SFTP server as if it were a local
filesystem, and then you can traverse that.

In Linux, "FUSE" allows people to write modules which do this. See
http://en.wikipedia.org/wiki/Filesystem_in_Userspace
and follow the links to FTPFS, SSHFS etc.

Supplementary answer: it's also possible to abstract away local vs
remote file operations to some degree, see for example open-uri.rb in
the standard library. As far as I know, this hasn't been done to the
level you are seeking. But feel free to have a go at implementing it
yourself :) You may find that you are stumped by the limited support
for ctime / chmod / chown etc by protocols like FTP.
 
C

Caleb Clausen

Short answer: no.

Long answer: Ruby's Dir and File classes just sit on top of the
file/directory operations provided by the underlying operating system.
For example, Dir.pwd and Dir.chdir refer to the process's (local)
current working directory.

However, on some systems, if you install the right tools, you may be
able to 'mount' a remote FTP or SFTP server as if it were a local
filesystem, and then you can traverse that.

In Linux, "FUSE" allows people to write modules which do this. See
http://en.wikipedia.org/wiki/Filesystem_in_Userspace
and follow the links to FTPFS, SSHFS etc.

Supplementary answer: it's also possible to abstract away local vs
remote file operations to some degree, see for example open-uri.rb in
the standard library. As far as I know, this hasn't been done to the
level you are seeking. But feel free to have a go at implementing it
yourself :) You may find that you are stumped by the limited support
for ctime / chmod / chown etc by protocols like FTP.

Or you can use a network file system such as nfs or samba, which makes
remote files appear local to all programs on your computer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top