Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am a beginner in perl, i am trying to get a file from remote machine using Net::SSH2 scp_get method. To get a small size file it's working fine, but when i try for getting any file greater than 1.5 MB then it gives a error message and quits or it just hangs up continuously & at times it even fails for small files also, can you please let me know where am i going wrong in implementing the script.

my $ssh2 = Net::SSH2->new(); $ssh2->debug(1); $ssh2->connect($host) or die " Cannot connect to 219 "; die " Username/password is wrong " unless $ssh2->auth(username=>$user, + password=>$password); $ssh2->scp_get('/path/somefile'); print " Successfully copied \n"; print $ssh2->error; $ssh2->disconnect();

Error Message:

Net::SSH2::Channel::read(size = 8192, ext = 0) - read 2972 bytes - read 4172 bytes - read -37 bytes - read 7144 total -24LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED in Net::SSH2

Thanks in advance
pradeep

Replies are listed 'Best First'.
Re: Net::SSH2 fails for scp_get method
by Gangabass (Vicar) on Sep 05, 2007 at 00:48 UTC

    Possible reasons for this error (as you can see in packet.c):

    • The current receive window is full, data ignored
    • Remote sent more data than current window allows, truncating
Re: Net::SSH2 fails for scp_get method----solution
by zentara (Cardinal) on Jun 20, 2012 at 14:39 UTC
    Hi, I was just checking this out, and although this node is old, for the benefit of people searching, here is how to do it. In your case, scp_get needs a blessed reference to write to, like an IO::File or IO::Scalar object. You just can't specify the file. Below is a working example
    #!/usr/bin/perl use warnings; use strict; use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->debug(1); $ssh2->connect('localhost') or die "Unable to connect Host $@ \n"; $ssh2->auth_password('z','ztester') or die "Unable to login $@ \n"; my $dir = '/home/z'; #get a large file like a 100Meg video file my $remote1 = $dir.'/hamps_boogie.flv'; use IO::File; my $local1 = IO::File->new("> 2.flv"); #it needs a blessed reference $ssh2->scp_get($remote1, $local1) or die "$!\n"; # be warned that you cannot have blocking set to 0 # from perldoc Net::SSH2 # blocking ( flag ) # Enable or disable blocking. Note that if blocking is disabled, # methods that create channels may fail, e.g. "channel", "SFTP", "scp_ +*".

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh