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


Hi,

I was trying to write a PERL code that would map to a remote network folder and pull osme files from there to the local machine.

This is the code snippet:

----------------------------------------------------

use Win32::OLE;

use File::Copy;



$strDrive = $ARGV[0];



# e.g. N:

$strPath = $ARGV1;


unless (-d $strPath )

{

print "Folder $source does not exist! \n";

die;
}


$boolPersistent = 0;


# True = Persistent ; False = Not Persistent

# ------ END CONFIGURATION ---------



$WshNetwork = Win32::OLE->new('WScript.Network');



eval

{

$WshNetwork->MapNetworkDrive($strDrive, $strPath, $boolPersistent, '', '') or print "Map network drive failed! original error: $! \n";
};

----------------------------------------------------



Now, I have a couple of questions:



1) The code worked just fine when i tried to test it on my machine; but the code should actually be deployed on our server - when i tried running it on our server (from where it would map to a remote server folder), the code just won't work!


I know that this is probably not a PERL question, maybe a Windows Server question, but owuld be good if someone can throw some light as to what might be wrong!


2) This line:


$WshNetwork->MapNetworkDrive($strDrive, $strPath, $boolPersistent, '', '')

a) I tried googling, but could not get much info! Does this API return anything? The return value seems to be empty even in the case of a successful map!



b) How can i catch an exception if this API fails?



c) This API returns " Bad file descriptor" error even if the API maps to the remote folder successfully!! What would this error mean then?!





Thanks and regards

Biswanath

Replies are listed 'Best First'.
Re: Mapping a remote network folder....
by Bloodnok (Vicar) on Mar 25, 2009 at 19:24 UTC
    You might want to...
    • Enclose your code in code tags (<code>...</code> tags).
    • Use strictures (use warnings; use strict;
    • Check & report any error status returned by the $WshNetwork = Win32::OLE->new('WScript.Network'); call ... by using Win32::OLE->LastError (see Win32::OLE).
    A user level that continues to overstate my experience :-))
Re: Mapping a remote network folder....
by Corion (Patriarch) on Mar 26, 2009 at 07:58 UTC

    Why do you want to map a network drive? You can simply copy the files directly by using their UNC name:

    use File::Copy; cp "\\\\$machine\\$sharename\\some\\directory\\and\\a\\file.txt", "her +e.txt" or die "Couldn't copy: $!";