ssr1012 ssr1012 - 1 year ago 100
Perl Question

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;

print "Enter the project \& Destination Folder: ";
my $input_rec = <STDIN>;
if($input_rec=~m/(exit|q|x)/i) { exit; }
elsif(!$input_rec && $input_rec eq '') { }
elsif($input_rec!~m/(\s|\t)/s) { }
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");

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.

Answer Source
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!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download