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

Hey all, doing what I thought was going to be a quick little CGI to view log info...HA! Trying to list the files in a directory on a mapped drive. opendir(...) is resulting in error 'No such file or directory'. The path works when the drive is local (e.g. c:/logfiles/monitor), but returns the above error when the drive is mapped (e.g. z:/logfiles/monitor). System running this CGI is Win XP Pro and mapped drives are Win XP Pro ad Win2k server...all NTFS. I've included the code in case yas feel like looking and telling me where I've gone wrong. After staring at this script all day (15 minutes writing and 5 hours staring and drooling.). :P Any help would be appreciated.
#! perl -wT use CGI; use strict; my $cgi = new CGI; my $dir = $cgi->param("server"); print $cgi->header(); print <<END; <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +"> <title>Logs</title> </head> <body bgcolor="#e7e7e7" text="#000000" link="#1346ad" alink="#1346ad" +vlink="#1346ad"> <font face="Arial"> END # ADD SERVER NAMES AND PATHS TO THIS CONIDTION BLOCK if($dir eq 'server1') { $dir = 'z:/logfiles/monitor'; } elsif($dir eq 'server2') { $dir = 'y:/logfiles/monitor'; } print "<b><u>", $cgi->param("server"), " logfiles at $dir</u></b><br>" +; # GET ALL CONTENTS OF THE DIRECTORY opendir(DIR, $dir) || print "<font color=\"#ff0000\">Problem: <i>$!</i +></font>"; while(my $file = readdir(DIR)) { # IF NOT A DIRECTORY, PRINT FILENAME if(!-d "$dir/$file") { print "<a href=\"/cgi-bin/admin/displayLog.pl?file=$dir/$file\ +">$file</a><br>"; } } closedir(DIR); print "</font>"; print $cgi->end_html();

Replies are listed 'Best First'.
Re: List files on mapped drive
by BrowserUk (Patriarch) on Jun 08, 2004 at 00:13 UTC

    By default, webserver userids (IUSER_<computer_name> and similar) do not have the privaleges to access network resources. This is a security measure and you should think carefully about the implications before you enable them to do so.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail

      Of course, you're assuming that the user is using the IIS server. Apache (on my system anyhow) runs as the local system account.

        In which case, you probably do not suffer the OP's problem, and my answer is therefore inapplicable to your situation.

        It is also possible that the OP is using Apache and has it set up to use a userid that is also severely restricted. In this case, the "or similar" applies. (Vaguely:)


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
Re: List files on mapped drive
by shonorio (Hermit) on Jun 08, 2004 at 14:44 UTC
    Hi SometimesMyHeadHurts

    Your apache are ruuning as services on XP ? If yes, maybe it's running as LocalSystem account and LocalSystem can't use network resource.
    Other, the driver is mapped for the current user, if you want to use a mapped drive on your apache running as services, you must to map his first

    Solli Moreira Honorio
    Sao Paulo - Brazil
      Yes, Apache is running as a service. And I once again forgot to set the Log On for the service to Administrator after a new build (I always do that :P). I've done that now. However, I am still encountering the same error.