perlboer has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

The folowing script I got.
When it's browse local dir's output is ok.
If it's browsing local shared dir's output is ok.

If it's browsing remote shared dir's we get following error : Can't chdir to //NLHUB515025T/sh_robert No such file or directory.
Is there an other way to read files and dirs on a remote drive?
#!perl -w use strict; use CGI; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $cgi = new CGI(); my $url = "/cgi-bin/index/index-tp.pl"; my $docroot = "//NLHUB515025T/sh_robert/"; my $docdir = $cgi->param("Dir") || ""; print $cgi->header(); my $newStyle=<<END; <!-- body { font-size: 10pt; font-family: sans-serif; } --> END print $cgi->start_html(-title=>'Browse directory', -style=>{-code=>$newStyle} ); if (-d "$docroot$docdir") { chdir("$docroot$docdir") or die "Can't chdir to $docroot$docdir\n" +; opendir(DIR, "$docroot$docdir") or die "Can't open directory $docr +oot$docdir\n"; my @entries = grep({! /^\.{1,2}\z/} readdir(DIR)); closedir(DIR); my @dirs = grep({ -d } @entries); my @files = grep({ -f } @entries); my $dircount = $#dirs + 1; my $filecount = $#files + 1; my $dirhtml = ""; foreach (sort(@dirs)) { $dirhtml .= "[" . $cgi->a({href => "$url?Dir=$docdir/$_"}, $_) + . "] "; } if ($dircount > 0) { print $cgi->p($cgi->strong("Subdirectories of $docdir"), $cgi- +>br(), $cgi->span({style => "background-color : #dddddd"}, $dirhtml)) +; } if ($filecount > 0) { print $cgi->start_table({border => 0, cellspacing => 0, cellpa +dding => 0}); print $cgi->start_table({border => 0, cellspacing => 0, cellpa +dding => 0}); print $cgi->Tr($cgi->th({align => "left"}, [("Filename", "&nbs +p;Size", "&nbsp;Date", "Time")])); foreach (sort(@files)) { my $size = (stat($_))[7]; my $mtime = (stat(_))[9]; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $ +isdst) = localtime($mtime); my $date = sprintf("&nbsp;%04d-%02d-%02d&nbsp;", $year + 1 +900, $mon + 1, $mday); my $time = sprintf("%02d:%02d", $hour, $min); print $cgi->Tr($cgi->td($cgi->a({href => "$docdir/$_"}, "$ +_&nbsp;")), $cgi->td({align => "right"}, $size), $cgi->td([$date, $ti +me])); } print $cgi->end_table(); } print $cgi->p($cgi->em("Directories:&nbsp;", $dircount, "&nbsp;-&n +bsp;Files:&nbsp;", $filecount)); } print $cgi->end_html();




Thank you in advance,

perlboer

Replies are listed 'Best First'.
Re: remote directory browsing give no listing
by Anonymous Monk on Oct 03, 2008 at 10:30 UTC
    "not functioning" isn't a description of the problem (or an error message). Say your garden hose is not functioning, is it leaking? no water coming out? red water? fire? magically suspended in air and immobile? :D

    Its definitely, probably definitely the permissions :)(your webserver runs the program under some account which doesn't have permission).

      Actually "not functioning" is *a* description of the problem. It is exactly what you get from lawyers and politicians; 100% accurate and totally useless :).

      That said, I would not suspect permissions, as he is checking the return to opendir. I believe that it would fail if there were permissions problems. I would look at the unfiltered results from readdir, as well as check its return.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: remote directory browsing give no listing
by perlboer (Acolyte) on Oct 13, 2008 at 19:17 UTC
    Solved!
    Authentication issue.
    Thanks again for the support.

    Regards Perlboer