note
tokpela
<p>
This is pretty easy really - you just open the file using the UNC.</p>
<p>
Basically, opening a file on a network drive can be accomplished by using the UNC filepath:
</p>
<p>
<code>
my $unc = '//10.1.0.22/path/to/use';
open(my $fh, $unc) or die "[Error] COULD NOT OPEN FILE: [$unc] - [$!]";
</code>
</p>
<p>
If you need to connect to the network drive you have two options.
</p>
<p>
One option is to create a mapped drive.</p>
<p>You could do this directly through Windows using the NET USE command:
<code>
net use x: \\computer name\share name
</code>
or
<code>
net use x: \\computer name\share name password /user:username
</code>
or a permanent map
<code>
net use x: \\computer name\share name password /user:username /persistent:yes
</code>
</p>
<p>
You could also accomplish this same thing using <a href="http://search.cpan.org/search?query=Win32%3A%3AFileOp">Win32::FileOp</a> by using the Map routine:
<code>
my $drive = 'X';
my $unc = '//10.1.0.22/path/to/use'
my $user = 'user';
my $pass = 'xyz';
Map $drive => $unc, { username => $user, passwd => $pass };
</code>
</p>
<p>
Finally, the second option is to connect to the network drive directly in the program which can be accomplished by using the Win32::FileOp Connect routine:
<code>
my $drive = 'X';
my $unc = '//10.1.0.22/path/to/use'
my $user = 'user';
my $pass = 'xyz';
Connect $drive => $unc, { username => $user, passwd => $pass };
</code>
</p>
785061
785061