【问题标题】:Perl Net::SSH2 scp_put returns unknown errorPerl Net::SSH2 scp_put 返回未知错误
【发布时间】:2017-10-05 02:00:17
【问题描述】:

我正在使用 Net:SSH2 通过 scp_put 将文件放在远程服务器上。 它返回未知错误:

-43,LIBSSH2_ERROR_UNKNOWN(-43),SCP 失败

似乎是在一些超时/延迟之后出现错误,因为它需要几分钟才能返回。

与 sftp-server 的连接正常。我可以从目录中获取目录列表。

我有权访问该目录,因为我可以使用 SFTP 客户端将文件放在那里。

我在 Windows 环境中使用 Strawberry Perl。

use warnings;
use strict;
use Net::SSH2;

my $dir1 = '.';
my $file = 'D:\\test\\test.txt';
my $ssh2 = Net::SSH2->new();
$ssh2->connect('testserver') or die "Unable to connect Host $@ \n";
$ssh2->auth_password('test','test') or die "Unable to login $@ \n";

if($ssh2->scp_put($file, $dir1)) {
            print "File $file transferred to $dir1\n";
} else {
            print "Couldn't transfer file $file to $dir1\n";
            print join ', ', $ssh2->error;
            print "\n";
}

【问题讨论】:

  • 如果您使用远程的完整路径(例如:'/home/user')而不是 cwd (.),它是否有效?
  • 使用完整路径时没有区别。目录列表适用于 cwd(.) 和完整路径,scp_put 不起作用。
  • 我可能不得不尝试 NET::SFTP:Foreign。我们在生产中的当前 Perl 设置中没有安装它。这就是我尝试使用 libssh2 和 scp_put 来管理它的原因。

标签: perl


【解决方案1】:

libssh2 中的 SCP 支持非常初级且有缺陷。

更好的替代方案是Net::SSH::Any,它具有适当的纯perl SCP 实现或Net::SFTP::Foreign 用于SFTP。两者都可以在 Net::SSH2 之上工作。

【讨论】:

    猜你喜欢
    • 2011-08-24
    • 2015-10-31
    • 2016-08-21
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多