I am trying to copy a files from one host to another host using :
Net::SCP::Expect
here is my program.
use strict;
use Net::SCP::Expect;
print "enter user name\n";
my $username = <>;
print "enter password\n";
my $pass = <>;
print "enter host name\n";
my $host = <>;
my $src_path = "/";
my $dst_path = "/";
my $scpe = Net::SCP::Expect->new(user=>$username, password=>$pass, auto_yes=> '1');
$scpe->scp($host.":".$src_path, $dst_path);
I am getting error as bad password.how to give user name and password as a input in scp module?
All three variables you are reading also contain the
\n
at the end.Remove it with
chomp
Beware that the password will be visible on the user's screen. You could take a look at Term::ReadPassword to avoid echoing of the characters on the screen.
Edit
chomp
modifies the supplied variable and return the number of characters removed. In your casechomp($username)
will return 1 as it removed one character. You have to call it beforescp
From the linked documentation (emphasis mine)