Perl Net::SFTP::Foreign disconnect 不关闭连接
Perl Net::SFTP::Foreign disconnect not closing the connection
虽然调用 $sftp->disconnect()
连接没有关闭并且 Perl 脚本处于挂起状态,直到我手动终止进程。
下面是我们如何创建 SFTP 连接的代码:
my %sftp_args = ( user => $username, autodie => 1, stderr_discard => 1,more => qw(-v),
timeout => $timeout_secs,ssh_cmd => $SSH_PATH );
my $sftp = Net::SFTP::Foreign->new($remote_host, %sftp_args);
当我们调用断开连接方法时脚本挂起。
$sftp->disconnect();
我尝试将断开连接设置为 eval under alarm,但它仍然没有恢复。
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 25;
my $retrun = $sftp->disconnect();
alarm 0;
};
my $exception = $@;
msg("Error Dump".Dumper($exception));
}
以下是我在 nohup.out 文件中遇到的错误。
bash: line 1: 27860 Alarm clock sftp_connection.pl
在对 Net::SFTP::Foreign 模块进行分析后,我找到了解决方案。所以 Net::SFTP::Foreign 模块有一个错误,下面是详细信息,我在 perldoc 中找到了这个:
On some operating systems, closing the pipes used to communicate the
slave SSH process does not terminate it and a work around has to be applied.
If you find that your scripts hung when the $sftp object gets out of scope,
try setting $Net::SFTP::Foreign::dirty_cleanup to a true value
根据上面的评论,我在我的应用程序中进行了更改,现在它运行良好:
my %sftp_args = ( user => $username, autodie => 1, stderr_discard => 1,
timeout => $timeout_secs, ssh_cmd => $SSH_PATH, dirty_cleanup => 1 );
my $sftp = Net::SFTP::Foreign->new($remote_host, %sftp_args);
return $sftp;
虽然调用 $sftp->disconnect()
连接没有关闭并且 Perl 脚本处于挂起状态,直到我手动终止进程。
下面是我们如何创建 SFTP 连接的代码:
my %sftp_args = ( user => $username, autodie => 1, stderr_discard => 1,more => qw(-v),
timeout => $timeout_secs,ssh_cmd => $SSH_PATH );
my $sftp = Net::SFTP::Foreign->new($remote_host, %sftp_args);
当我们调用断开连接方法时脚本挂起。
$sftp->disconnect();
我尝试将断开连接设置为 eval under alarm,但它仍然没有恢复。
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 25;
my $retrun = $sftp->disconnect();
alarm 0;
};
my $exception = $@;
msg("Error Dump".Dumper($exception));
}
以下是我在 nohup.out 文件中遇到的错误。
bash: line 1: 27860 Alarm clock sftp_connection.pl
在对 Net::SFTP::Foreign 模块进行分析后,我找到了解决方案。所以 Net::SFTP::Foreign 模块有一个错误,下面是详细信息,我在 perldoc 中找到了这个:
On some operating systems, closing the pipes used to communicate the
slave SSH process does not terminate it and a work around has to be applied.
If you find that your scripts hung when the $sftp object gets out of scope,
try setting $Net::SFTP::Foreign::dirty_cleanup to a true value
根据上面的评论,我在我的应用程序中进行了更改,现在它运行良好:
my %sftp_args = ( user => $username, autodie => 1, stderr_discard => 1,
timeout => $timeout_secs, ssh_cmd => $SSH_PATH, dirty_cleanup => 1 );
my $sftp = Net::SFTP::Foreign->new($remote_host, %sftp_args);
return $sftp;