Hi,
in a similar situation I make a temporary drive connection. The
usernames/passwords are kept in the file .netrc in the home directory of
the user executing the script (might be a security issue) and accessed via
the Net::Netrc module. You could avoid the whole drive mumbo-jumbo if you
connect/disconnect to the IPC$ share of the server.
HTH,
Ekkehard
my $server = "servername";
my $share = "//servername/share";
$share =~ s|/|\\|g;
# Look up 'credentials'
my $mach = Net::Netrc->lookup($server);
my $login = $mach->login();
my $password = $mach->password();
# Missing: check whether login, password are defined
# Drive selection
my %seen = ();
my @availableDrives = ();
# Drives already in use
my @connectedDrives = Win32::AdminMisc::GetDrives();
foreach (@connectedDrives){ s/\\//; }
# Do an intersection of 'all' and 'connected'
@[EMAIL PROTECTED] = ();
foreach my $d (@allDrives)
{ push(@availableDrives, $d) unless exists $seen{$d};}
# Select a drive at random
my $drive = $availableDrives[ rand @availableDrives ];
# Do the connect
my %useinfo = (
type => &RESOURCETYPE_DISK,
localname => $drive,
remotename => $share,
username => $login,
password => $password,
);
my $result = Win32::Lanman::WNetAddConnection(\%useinfo);
if(!$result)
{
my $error = Win32::Lanman::GetLastError();
# whatever
}
# Do something, e.g. your copy (using UNC paths or the drive letter)
# Disconnect
if(!Win32::Lanman::WNetCancelConnection($drive, &CONNECT_UPDATE_PROFILE,
1))
{
print "Sorry, could not disconnect $drive from $share: (" .
Win32::Lanman::GetLastError() . "\n";
# Whatever
}
"Ewen Marshall" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
04.02.2005 23:51
Please respond to ewen
To: <[email protected]>
cc: (bcc: Ekkehard Goerlach/PH/Novartis)
Subject: Coping Files Over Domains
Category:
Hi guys,
I'm looking for some help with coping files over domains. At
my work we have 92 domains, some trusted, most not, all on the same
subnet. I've created a back up check that scans the back up log files on
each of the 92 PDC's and emails the result to an email address. Instead of
emails I would rather create a text file and copy it over to a shared
folder on the web server. After some testing using the following code:
use File::Copy;
$source = "C:\\backup\\backup_check.txt";
$dest = "\\<WEB_SERVER_IP>\\backupcheck";
copy("$source","$dest") or die "Problem copying file!\n\n Error: $!\n\n";
I realised that some domains need a username/password to access the shared
folder on the web server. Does anyone know how I can copy a file with a
username and password along with the copy command or is there some other
module I can use to carry this out?
Thanks in advance for any help.
Ewen_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs