perl - Perl 文件通过 Net::SFTP::Foreign thows 传输错误:密码验证不可用
问题描述
我已经手动将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 时,它会分配一个伪终端来询问您的密码。这也解释了为什么您不能例如将密码发送到命令的标准输入。
推荐阅读
- c++ - 在“ios::in|ios::out”模式下处理文件时,fstream 类是否维护两个缓冲区?C++
- java - 由 maven 插件创建的 Uber/Fat jar 导致 tibco jar 出现问题
- r - 如何用 gsub 清理括号?
- php - 当我发送邮件“$mail->send();”时得到空值 从发送功能
- android - Firebase 推送通知不会弹出,只是显示在通知栏中
- database - Laravel Eloquent 使用 'with' 检索数据并根据此 'with' 中的值进行查找
- javascript - 如何对键数组进行排序:基于对象值的对象
- javascript - 如何限制textarea中每行的字符数?
- python - 如何使用 Python 和 OpenCV 实现良好的边缘检测来校准一些非常小的东西
- node.js - 创建一个接受变量输入文件的节点 api