ssr1012
ssr1012

Reputation: 2589

Copy the files and folders recursively with the same permissions/previleges using Perl & ROBOCOPY

I am trying to copy the files and folders (Including subfolders) to the destination folder (which is getting from User end) by ROBOCOPY. However, I don't have permission to create the folder on destination. I am having the administrator username and password. How to implement this code to use the username/password in this script or batch file. (Don't consider the "project" getting from user)

use strict;
use warnings;
use Cwd;

while(1)
{
    print "Enter the project \& Destination Folder: ";
    my $input_rec = <STDIN>;
    chomp($input_rec);
    if($input_rec=~m/(exit|q|x)/i) {  exit;  }
    elsif(!$input_rec && $input_rec eq '') { }
    elsif($input_rec!~m/(\s|\t)/s) { }
    else
    {
        my ($dept, $dest) = split /\s/, $input_rec;
        print "DEPT: $dept\t$dest\n";
        system("ROBOCOPY \\\\server1\\Robo\\Source\\ISBN \\\\server2\\Robo\\Source\\ISBN /MIR /SEC /SECFIX");
        exit;
    }
}

Or ELSE I need to copy files and folders without ROBOCOPY using perl script to the destination folders with using administrator credentials which is not user can able to access.

The task is, if user requested admin to create a folders/subfolders with rights/permissions/structure as it is in the source original and its should be created by admin as well requested destination by user end. Each and every time admin can't do this hence we have trying to automate this process. User can't access the server to copy the folders.

It would be appreciated if anyone suggested how to solve this.

Upvotes: 0

Views: 1159

Answers (2)

user6572950
user6572950

Reputation:

my $source = "\\\\server1\\Robo\\Source\\ISBN";
print "DEPT: $dept\t$dest\n"; #$dest = "\\\\server2\\Robo\\Destination\\ISBN";
system("net use $source /user:.\\\\\administrator xxxx");
system("net use $dest /user:.\\\\administrator xxxx");
system("ROBOCOPY $source $dest /MIR /SEC /SECFIX");

The above lines supports to copy the files and folders as per the actual privileges to the destinations. Hope its great day!

Upvotes: 1

Korsakof
Korsakof

Reputation: 56

You can use something intermediate. You can create a scheduled task on windows with the rights of the user. You should create as "One time" task. You can launch as many as you want.

Task view User

You can invoke from your perl script with this command.

SCHTASKS /RUN /TN "Name of the task"

Its an idea. I hope this helps.

Upvotes: 1

Related Questions