gpt4 book ai didi

linux - 无法在 Perl 中使用 Net::SFTP 模块

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:53:58 27 4
gpt4 key购买 nike

我在我的 Linux Ubuntu 机器上使用 perl,v5.10.1。我尝试通过 cpan 提示安装 Net::SFTP 模块,但它在过去 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 路径中添加所有必需的模块路径。我是这里的根用户。

最佳答案

Can't locate 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

I don't want to add all the required module's paths in @INC path in the beginning of my script

然后确保 @INC 包含安装模块的路径。你可以通过

export PERL5LIB=/home/foobar/code(对于 Linux)(将其添加到 ~/.bashrc 以使其在您登录时始终可用。)

set PERL5LIB = c:\path\to\dir(对于 Windows)

关于linux - 无法在 Perl 中使用 Net::SFTP 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23949184/

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