Perl Net :: SSH2 scp_put puts the file and then freezes

I use the net :: SSH2 scp_put method to place a single file in my home directory on a Unix server from a Windows window. I am using Strawberry Perl 5.12 (portable version). I installed the libssh2 1.2.5 binaries and then Net :: SSH2 from cpan.

Here is my code snippet:

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

Output (edited for anonymity):

created an SSH object \ n

connected to host \ n

authenticated \ n

libssh2_scp_send_ex (ss-> session, path, mode, size, mtime, atime) → 0x377e61c \ n

Net :: SSH2 :: Channel :: read (size = 1, ext = 0) \ n

Then it hangs forever (> 40 minutes in one test) and needs to be killed.

, scp ! , . StackOverflow .

- : 1) 2) ( ) , , scp ?

, !

+3
3

alarm(), , "alarm.pl", , :

use strict;
use warnings;
use 5.10.0;

# pretend to be a slow process if run as 'alarm.pl s'
if (@ARGV && $ARGV[0] eq 's') {
    sleep(30);
    exit();
}

# Otherwise set an alarm, then run myself with 's'
eval {
    local $SIG{ALRM} = sub {die "alarmed\n"};
    alarm(5);
    system("perl alarm.pl s");
};
if ($@) {
    die $@ unless $@ eq "alarmed\n";
    say "Timed out slow process";
}
else {
    say "Slow process finished";
}
0

Net:: SFTP:: Foreign Net:: SSH2, Net:: SFTP:: :: Backend:: Net_SSH2:

use Net::SFTP::Foreign;

my $sftp = Net::SFTP::Foreign->new($host, user => $user, password => $password, backend => Net_SSH2);
$sftp->die_on_error("Unable to connect to remote host");

$sftp->put($file, $remotelocation);
$sftp->die_on_error("Unable to copy file");

, plink ( PuTTY) Net:: SSH2.

0

I don’t think it hangs, it’s just REALLY SLOW. 10 times slower than it should be. The reason the file seems to be because it selects the file before it is completed. This is not too unexpected, Perl is finding new ways to frustrate and frustrate programmers on a daily basis. Sometimes it seems to me that I spend more time studying the features of Perl and learning 10 slightly different ways to do the same thing as doing the real job.

-1
source

All Articles