简体   繁体   English

Perl 通过 Net::SFTP::Foreign thows 传输文件错误:密码验证不可用

[英]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.我已手动将Net::SFTP::Foreign模块文件(因为无权安装 perl 模块)添加到我当前的工作目录。 My SFTP transfer script shown below:我的 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";

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.此错误是否是因为未安装模块IO::Pty

When I manually transfer files using sftp command it works, but through script its not.当我使用sftp命令手动传输文件时,它可以工作,但通过脚本却不行。

The underlying process (be it sftp of scp or whatever) needs to get the password from the Perl program.底层进程(无论是 scp 的 sftp 还是其他)需要从 Perl 程序中获取密码。 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.这就是为什么需要IO::Pty的原因。

When you run sftp in a terminal, it allocates a pseudo terminal to ask you for the password.当您在终端中运行 sftp 时,它会分配一个伪终端来询问您的密码。 That also explains why you can't eg send the password to the standard input of the command.这也解释了为什么您不能例如将密码发送到命令的标准输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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