【发布时间】:2011-08-24 11:31:46
【问题描述】:
我正在使用 Net::SSH2 的 scp_put 方法从 Windows 机器将一个文件放在 Unix 服务器上的主目录中。我正在使用草莓 Perl 5.12(便携版)。我安装了 libssh2 1.2.5 二进制文件,然后从 cpan 安装了 Net::SSH2。
这是我的代码 sn-p:
sub uploadToHost{
my $file=@_[0];
my $host=@_[1];
my $user=@_[2];
my $pass=@_[3];
my $remotelocation=@_[4];
#makes a new SSH2 object
my $ssh=Net::SSH2->new() or die "couldn't make SSH object\n";
#prints proper error messages
$ssh->debug(1);
#nothing works unless I explicitly set blocking on
$ssh->blocking(1);
print "made SSH object\n";
#connect to host; this always works
$ssh->connect($host) or die "couldn't connect to host\n";
print "connected to host\n";
#authenticates with password
$ssh->auth_password($user, $pass) or die "couldn't authenticate $user\n";
print "authenticated $user\n";
#this is the tricky bit that hangs
$ssh->scp_put($file, $remotelocation") or die "couldn't put file in $remotelocation\n";
print "uploaded $file successfully\n";
$ssh->disconnect or die "couldn't disconnect\n";
} #ends sub
输出(为匿名编辑):
创建 SSH 对象\n
连接到主机\n
已通过身份验证\n
libssh2_scp_send_ex(ss->session, path, mode, size, mtime, atime) -> 0x377e61c\n
Net::SSH2::Channel::read(size = 1, ext = 0)\n
然后它会永远挂起(在一次测试中 > 40 分钟)并且需要被杀死。
奇怪的是它实际上确实将文件scp到远程服务器!它只是在它应该完成后挂起。我在 StackOverflow 或其他地方找不到对这个奇怪问题的引用。
谁能指出我正确的方向 1) 阻止它挂起,或 2) 实现(作为一种解决方法)一个计时器,它会在几秒钟后终止这个命令,这是足够的时间来 scp 文件?
谢谢大家!
【问题讨论】: