我已将Net::SFTP::Foreign
模块文件手动添加到我的当前工作目录中(因为无权安装perl模块)。我的SFTP传输脚本如下所示:
#!/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";
但是此脚本引发了一个错误:
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
此错误是否是由于未安装模块IO::Pty
造成的。
当我使用sftp
命令手动传输文件时,它可以工作,但不能通过脚本来传输文件。
答案 0 :(得分:2)
基础进程(无论是scp的sftp还是其他)都需要从Perl程序中获取密码。密码的传输不会破坏安全性,即必须通过伪终端进行传递。这就是为什么需要IO::Pty。
在终端中运行sftp时,它将分配一个伪终端来询问您的密码。这也解释了为什么您不能将密码发送到命令的标准输入。