gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:11:09 25 4
gpt4 key购买 nike

我手动添加了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 手动传输文件时命令它工作,但通过脚本它不是。

最佳答案

底层进程(无论是 scp 的 sftp 还是其他)需要从 Perl 程序中获取密码。密码的传递不能破坏安全性,即必须通过伪终端传递。这就是为什么IO::Pty是必须的。

当您在终端中运行 sftp 时,它会分配一个伪终端来询问您的密码。这也解释了为什么你不能,例如将密码发送到命令的标准输入。

关于通过 Net::SFTP::Foreign thows 的 Perl 文件传输错误:密码验证不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61326964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com