我在Linux Ubuntu机器上使用perl,v5.10.1。我尝试通过Net::SFTP
提示安装cpan
模块,但在过去2天内发出以下错误。
警告:
Warning: no success downloading
'/root/.cpan/sources/authors/01mailrc.txt.gz.tmp19821'. Giving up on
it. at /usr/share/perl5/CPAN/Index.pm line 225
错误:
Connecting to www.perl.org|207.171.7.51|:80... failed: Connection
timed out.
Connecting to www.perl.org|207.171.7.41|:80... failed: Connection
timed out.
然后我通过CPAN站点通过tar文件方法安装它。现在,当我运行下面的示例脚本时,它会向我抛出错误。
脚本:
use Net::SFTP;
my $host = "169.144.106.231";
my %args = (
user => "root",
password => "******" );
my $sftp = Net::SFTP->new($host, %args);
错误:
Can't locate Net/SSH/Perl/Buffer.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/perl5/Net/SFTP/Buffer.pm line 6.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Net/SFTP/Buffer.pm line 6.
Compilation failed in require at /usr/local/share/perl5/Net/SFTP/Attributes.pm line 7.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Net/SFTP/Attributes.pm line 7.
Compilation failed in require at /usr/local/share/perl5/Net/SFTP.pm line 8.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Net/SFTP.pm line 8.
Compilation failed in require at ankur_sftp.pl line 6.
BEGIN failed--compilation aborted at ankur_sftp.pl line 6.
我没有安装Net/SSH/Perl/Buffer.pm
,而Buffer.pm
等少数模块正在其他路径上停留。
/root/Net-SFTP-0.10/blib/lib/Net/SFTP/Buffer.pm
/root/Net-SFTP-0.10/lib/Net/SFTP/Buffer.pm
我的@INC
包含
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
usr/lib64/perl5
/usr/share/perl5
有人可以帮忙吗?为什么cpan
提示方法会抛出该错误?接下来对于tar文件方法,如果存在模块依赖问题,那么如何使用CPAN tar文件方法解决它?另外,如何在正确的路径上安装模块,因为我不想在脚本开头的@INC
路径中添加所有必需的模块路径。我是root用户。
答案 0 :(得分:3)
找不到Net / SSH / Perl / Buffer.pm
这意味着缺少Net::SSH::Perl::Buffer
模块。你需要安装它。
Net / SFTP / Buffer.pm与Net :: SSH :: Perl :: Buffer不同。
您正面临依赖性问题,要么您必须转到CPAN并下载tar文件并安装模块,您必须为每个缺少的模块执行此操作。我建议您尝试使用CPAN客户端或App :: cpanminus,以便可以自动安装依赖项。
为此,请参阅:Installing perl dependency automatically in perl
我不想在@INC路径中添加所有必需模块的路径 我脚本的开头
然后确保@INC
包含安装模块的路径。你可以通过
export PERL5LIB=/home/foobar/code
(对于Linux)(将此添加到~/.bashrc
以使其在您登录时始终可用。)
set PERL5LIB = c:\path\to\dir
(适用于Windows)