I have a script which establishes connection to remote server using Perl module Net::OpenSSH and transfers files from local server to remote machine. This works perfectly fine.
...
my $ssh = ConnectToServer( $host, $user, $password );
my $remote_dir = "/home/shared/some/path/"
if ( $ssh->system('mkdir', '-p', $remote_dir) ) {
print "Directory $remote_dir created!\n";
} else {
print "Can't create $remote_dir on $host : ".$ssh->error."\n";
}
$ssh->scp_put({glob => 1}, "/home/shared/Test_Vinod/LOG/*.zip", $remote_dir)
or die "scp failed: " . $ssh->error;
undef $ssh;
sub ConnectToServer {
my ( $host, $user, $passwd ) = @_;
my $ssh = Net::OpenSSH->new($host,
user => $user,
password => $passwd,
master_opts => [-o => "StrictHostKeyChecking=no"]
);
$ssh->error and die "Couldn't establish SSH connection: ". $ssh->error;
return $ssh;
}
But whenever I execute this script I get message:
Directory /home/shared/some/path/ created!
My understanding on line if ($ssh->system('mkdir', '-p', $remote_dir)) { is:
If $remote_dir doesn't exists create it recursively on remote machine.
But how the value of $ssh->system('mkdir', '-p', $remote_dir) becomes 1 even when directory already exists.
Maybe I am confused with -p flag. Experts comments expected. Thanks.