Thanks to mpapec
I added a new function for this and it works now
use Win32::NetResource qw/GetUNCName AddConnection CancelConnection/;
use Win32API::File qw/ CopyFile fileLastError /;
sub getNetworkDrive {
my ($share_name, $user_name, $password) = @_;
my $drive;
for my $letter ('g' .. 'z' ) {
my $mapped;
$drive = "$letter:";
GetUNCName( $mapped, $drive );
last if not $mapped;
}
my $share = {
RemoteName => $share_name,
LocalName => $drive,
};
print "connecting $share->{RemoteName} to $share->{LocalName}\n";
if( not AddConnection( $share, $password, $user_name, 0 )) {
die "connection error:\n", win32err();
}
for my $file( @ARGV ) {
print "copying $file\n";
CopyFile( $file, "$share->{LocalName}$file", 0 )
or print "\tfailed: " . fileLastError() . "\n";
}
getNetworkDriveWithoutLogin($share->{LocalName}, "C:\\Projects\\Perl\\download\\");
if( not CancelConnection( $share->{LocalName}, 0, 1 )) {
print "disconnection error:\n", win32err();
}
}