Hello list,
I have a module that encapsulates the mapping of a drive letter to a
remote share and copying a local file to the remote share. It works just
fine when used from the command line, however, when run from a CGI
within IIS it complains (probably quite rightly) about a specfied
session not existing.
It is the AddConnection() call that is failing below. From what I can
glean from the documentation, the fourth parameter (set here to 0) is a
reference to a suitable connection, but I don't know how to set that up.
Any ideas or suggestions would be gratefully appreciated.
Thanks,
David
package Remote::Filecopy;
use strict;
use warnings;
use constant SHARE_NAME => '\\\\a\\b';
use constant USER_NAME => 'user';
use constant PASSWORD => 'pw';
use Carp qw/ carp croak /;
use Win32::NetResource qw/ GetUNCName AddConnection CancelConnection /;
use Win32API::File qw/ CopyFile fileLastError /;
use Exporter;
use vars qw/ @ISA @EXPORT_OK $VERSION /;
@ISA = qw/ Exporter /;
$VERSION = '0.1';
my $SHARE = {
RemoteName => SHARE_NAME,
LocalName => undef,
};
push @EXPORT_OK, 'filecopy';
sub filecopy {
my %args = @_;
if( not defined $SHARE->{LocalName} ) {
$SHARE->{LocalName} = free_drive_letter();
if( not AddConnection( $SHARE, PASSWORD, USER_NAME, 0 )) {
croak "share connection error:\n", win32err();
}
}
CopyFile( $args{from}, "$SHARE->{LocalName}$args{to}", 0 )
or carp "copy of [$args{from}] to
[$SHARE->{LocalName}$args{to}] failed: "
. fileLastError() . "\n";
}
sub free_drive_letter {
my $drive;
for my $letter ('f' .. 'z' ) {
my $mapped;
$drive = "$letter:";
GetUNCName( $mapped, $drive );
return $drive if not $mapped;
}
croak "All network drive letters (F: .. Z:) are in use\n";
}
END {
if( defined $SHARE->{LocalName} ) {
if( not CancelConnection( $SHARE->{LocalName}, 0, 1 )) {
carp "disconnection error:\n", win32err();
}
}
}
sub win32err {
my $err;
Win32::NetResource::GetError($err);
Win32::FormatMessage($err);
}
__END__
_______________________________________________
Perl-Win32-Web mailing list
Perl-Win32-Web@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs