remote readdir()

Discussion in 'Perl Misc' started by ARod, Jul 29, 2003.

  1. ARod

    ARod Guest

    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?
    ARod, Jul 29, 2003
    #1
    1. Advertising

  2. ARod

    Garry Short Guest

    Abigail wrote:

    > ARod () wrote on MMMDCXIX September MCMXCIII in
    > <URL:news:>:
    > ** 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
    Garry Short, Jul 29, 2003
    #2
    1. Advertising

  3. ARod

    pkent Guest

    In article <>,
    (ARod) wrote:

    > 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

    --
    pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
    Remove the tea to reply
    pkent, Jul 30, 2003
    #3
  4. On 29 Jul 2003 10:30:09 -0700,
    ARod <> wrote:
    > Garry Short <> wrote in message news:<bg60k7$mo4$2$>...


    >> 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";


    > 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
    --
    |
    Martien Verbruggen |
    Trading Post Australia | What's another word for Thesaurus?
    |
    Martien Verbruggen, Jul 30, 2003
    #4
  5. ARod

    Garry Short Guest

    ARod wrote:

    > 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
    Garry Short, Jul 30, 2003
    #5
  6. ARod

    programmer Guest

    > 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.
    programmer, Jul 30, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    2
    Views:
    734
  2. Ramon
    Replies:
    5
    Views:
    10,780
    John C. Bollinger
    Jan 3, 2005
  3. electric sheep

    readdir() and S_ISDIR(stat.st_mode) question (OT ?)

    electric sheep, Mar 4, 2004, in forum: C Programming
    Replies:
    2
    Views:
    11,510
    Villy Kruse
    Mar 4, 2004
  4. John Stoffel
    Replies:
    0
    Views:
    151
    John Stoffel
    Feb 6, 2009
  5. qanda
    Replies:
    9
    Views:
    163
    qanda
    Sep 11, 2003
Loading...

Share This Page