remote readdir()

A

ARod

Is there a way to use readdir to get the directory structure of a
remote server? If not, is there another function that can do this?
 
G

Garry Short

Abigail said:
ARod ([email protected]) wrote on MMMDCXIX September MCMXCIII in
<URL:** Is there a way to use readdir to get the directory structure of a
** remote server? If not, is there another function that can do this?


Yes. You first have to mount the directory you want to read though.
NFS and Samba are two protocols that are used often.

On Unix, you would do something like:

$ mount -t nfs remote.server.tla:/path/to/dir /mnt


Of course, if you want to do this often, or transparantly, you could
use the automounter.


Abigail

And if you're using some brand of Windoze,

my $remote = '\\remote_server\remote_share\file_structure_within_share';
readdir $remote or die "Can't READDIR $remote: $!\n";


Or, if you use double quotes to define $remote so that you can include a
variable, double-up the backslashes :

foreach $folder (@list) {
$remote = "\\\\server\\share\\$folder";
...
}

HTH,

Garry
 
P

pkent

Is there a way to use readdir to get the directory structure of a
remote server? If not, is there another function that can do this?

In the special case that the remote directory is available locally (say
as a mapped drive on Windows or mounted from the remote NFS export) then
you can read the directory just like any other. But I expect that isn't
the case here. What you'll need to do is somehow get the directory read
on teh remote machine and get the data to your local machine. There are
many ways of doing this, from CGI programs, RPC things, custom daemons,
custom inetd programs, to using ssh or rsh. Your options might be
limited by the operating systems involved, your network and so on.

P
 
M

Martien Verbruggen

Garry, I'm using Windows NT but your suggestion is not working.
Here's a snippet of the code:

$remote = "\\\\server\\some_share";

Don't use double quotes for this, use singles, unless you like
repeating all those backslashes.
opendir(DIRECTORY,$remote);

You forgot to check whether the opendir() succeeded. When you do, make
sure to include $! in your error message.
@dirs=readdir(DIRECTORY) or die "can't read $remote";

Your error message is misleading.
closedir(DIRECTORY);

The readdir fails...What am I doing wrong?

You forgot to check whether the opendir() succeeded.

If it fails, there could be a load of reasons, the most likely being
that you are not allowed to connect to that share without providing
credentials.

Martien
 
G

Garry Short

ARod said:
Garry, I'm using Windows NT but your suggestion is not working.
Here's a snippet of the code:

$remote = "\\\\server\\some_share";

opendir(DIRECTORY,$remote);
@dirs=readdir(DIRECTORY) or die "can't read $remote";
closedir(DIRECTORY);

The readdir fails...What am I doing wrong?

There's nothing wrong with the code per se - just ran it on my NT box and it
works fine. The trouble is you're not checking your results properly :

opendir(DIRECTORY,$remote) or die "Can't open DIR $remote: $!\n;
@dirs=readdir(DIRECTORY) or die "can't read $remote: $!\n";

Try that and the script will tell you why it fails.

BTW, a word of warning - the script will come back and say "No such file or
directory" if you don't have read access, which is a little misleading. If
you get this error and you know the share exists, try opening it within NT
(run command: "\\server\share")

HTH,

Garry
 
P

programmer

Is there a way to use readdir to get the directory structure of a
remote server? If not, is there another function that can do this?


I did this using Net::FTP and a recursive program that reads the root
directory, extracts the size of files and the name of directories.

It then calls itself for all directories, and accuumulates the sizes for all
files.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top