Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
# copy files to a remote share requiring authentication # # This program demonstrates how to find a free drive letter # on the local machine, setting up the shared connection, # copying the file over and then tearing down the connection # afterwards. I hope this helps someone else save the two hours # it took me to gather all the loose ends together. # # copyright (c) David Landgren 2005 # # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. use strict; use warnings; use Win32::NetResource qw/GetUNCName AddConnection CancelConnection/; use Win32API::File qw/ CopyFile fileLastError /; use constant SHARE_NAME => '\\\\remote_svr\\sharename'; # must use bac +kslashes use constant USER_NAME => 'myusername'; use constant PASSWORD => 'mysekretpassword'; 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"; } if( not CancelConnection( $share->{LocalName}, 0, 1 )) { print "disconnection error:\n", win32err(); } sub win32err { my $err; # Win32::GetError($err); -- bug spotted by puploki Win32::NetResource::GetError($err); Win32::FormatMessage($err); }

In reply to Copying files to an authenticated Win32 share by grinder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (14)
    As of 2015-07-02 17:29 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (44 votes), past polls