简体   繁体   中英

Perl file transfer through Net::SFTP::Foreign thows error: password authentication not available

I have manually added Net::SFTP::Foreign module files(since don't have access to install the perl modules) to my current working directory. My SFTP transfer script shown below:

#!/usr/bin/perl -I/home/vinod/scripts/sftp_test/lib

use strict;
use warnings;

use Net::SFTP::Foreign;

print "Starting the script execution\n";

my ($hostip, $username, $password) = ("xx.xxx.xxx.xxx", "user", "password");

my $rdir = "/home/shared_dir/Vinod";
my $fullfilename = "/home/vinod/scripts/sftp_test/abc.txt";

my $sftp = Net::SFTP::Foreign->new(host=>$hostip , user=>$username , password=>$password, more=>[qw(-v -o PreferredAuthentications=password)]) or die "Cannot open remote file list connection: $!";

$sftp->setcwd($rdir) or die "unable to change cwd: " . $sftp->error;

$sftp->put("$fullfilename", "$rdir/xyz.txt") or die "put failed: " . $sftp->error;

$sftp->disconnect;

print "Done\n";

But this script throws me an error:

Starting the script execution
password authentication not available, IO::Pty is not installed or failed to load: Can't locate IO/Pty.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 . /home/vinod/scripts/sftp_test/lib) at /home/vinod/scripts/sftp_test/lib/Net/SFTP/Foreign/Backend/Unix.pm line 256.
 at test.pl line 17

Whether this error is because of module IO::Pty not installed.

When I manually transfer files using sftp command it works, but through script its not.

The underlying process (be it sftp of scp or whatever) needs to get the password from the Perl program. The transfer of the password can't break the security, ie it must be passed via a pseudo-terminal. That's why IO::Pty is required.

When you run sftp in a terminal, it allocates a pseudo terminal to ask you for the password. That also explains why you can't eg send the password to the standard input of the command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM