The copy function of File::Copy can copy only a single file at a time, and it has to be called with a destination file name, not a directory. You could have learned that from the File::Copy documentation.

If you want to copy more than one file, you need a loop. If you want to copy an entire subtree, you need to recurse into source and destination directories. File::Copy::Recursive can do both, if you RTFM.

Regarding your privileges problem, you need to start your copy script as a privileged user. Windows has the runas command, and it offers the services infrastructure for a clean separation of a unprivileged user interface and a privileged background service. runas needs the Administrator password at runtime (and you don't want to give it away!), the service way doesn't. Remember that privileges require responsability, so use strict, use warnings, and enable the taint mode (#!perl -T). Verify all input and refuse to work when the input does not match the rules. Using a web server could be a simple workaround, for read accesss to the "restricted location", any web server could do the job, for write access, a WebDAV enabled webserver could do the trick. No need to invent new protocols. Of course, you also could use a file upload form and a CGI for write access.

Privilege separation can be a real pain under Windows, there are several attempts to clone the common su or sudo utilities, starting with a single batch file and ending with a huge services infrastructure. I still haven't seen any Windows utility as reliable and secure as sudo on Unix.

Think about your initial problem, or better: Explain it to us. Why do you think you need to to copy files from a restricted location using admin id and encrypted password? If the "restricted location" is the source, just make it world readable, but writeable only for the Administrator account. This can be done using standard Windows access controls. If the "restricted location" is the destination, you are defeating your restrictions, so just drop them and make it world (or group) writeable.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^3: perl script to copy files as admin by afoken
in thread perl script to copy files as admin by GreenWitch

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.