[Israel.pm] How to open a file on a network drive, using CGI - The solution !!

roi sh roi__ at hotmail.com
Wed May 5 05:25:51 PDT 2004


Hi All and thanks a lot for your effort and leads !!

The solution Pinhas and I have found is based on:

Module: Win32::NetResource      - a standard win32 ppm module
function: AddConnection(\%NETRESOURCE,$Password,$UserName,$Connection)

\%NETRESOURCE - a Hash defining the net resource
$ paswword: the password on the target network
$username: the username on the target network
$connection: 0 is non persistent

using the AddConnection function before opening the server directory enabled 
access to the
server directories.
note that i have defined only a few of the %NETRESOURCE Hush params.

the code looked like this:

# ---
#using CGI,  this code open a server on a network, and display the files 
under the server directory.

use Win32::NetResource

my $password = "[network password]";
my $UserName= "[network UserName]";
my $Host = "\\\\[server name]\\c\$\\[folder]\\[folder]\\[folder]";

my $Connection=0;
my %NETRESOURCE;
$NETRESOURCE{'Type'}=RESOURCETYPE_DISK;
$NETRESOURCE{'RemoteName'}=$Host;

my 
$Con=Win32::NetResource::AddConnection(\%NETRESOURCE,$password,$UserName,$Connection);
print "conection: $Con";

my $dir=$Host;
opendir(DIRHANDLE,$dir) or die "cant open $dir: $ !";
while(defined($filename=readdir(DIRHANDLE)))
{
print $filename;
}
close (DIRHANDLE);

my $Con=Win32::NetResource::CancelConnection(\%NETRESOURCE,$Connection,1);
print "conection: $Con";

# --- END


Roi.


###########################################

The problem: (as i wrote on 4 May 2004 was):

Hi.

Actualy it's a directory i'm trying to read.

the error as written in the Apache errors log:

[Tue May 04 02:13:59 2004] [error] [client [local IP]] can't open dir
\\[server name]\c$\[folder]\[folder]\[folder]\Log: No such file or directory
at c:\APACHE~1\apache\cgi-bin\OFFLIN~1.PL line 112.

lines 111, 112 are:
$directory = "\\\\[server name]\\c\$\\[folder]\\[folder]\\[folder]\\Log";
opendir(DIRHANDLE, $directory) or die "can't open dir: $directory: $!";

i also tried using the server IP instaed of its DNS name and it did not
work.



please note that  running the perl script itself (not the CGI), from inside
the network,  the direcctory is opened:
line 113 is: print (Dir $directory opened!") .
its result: Dir \\[server name]\c$\[folder]\[folder]\[folder]\Log opened!.

thanks.

Roi.

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus




More information about the Perl mailing list