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

I'm new to using SSH2 and would like some help. I seem to connect OK with my userID and password, but get a timeout error when I try to get a file.
code:

use Net::SSH2; use strict; my $host = "ftp.aaaa.com"; my $ssh2 = undef; $ssh2 = &connect($host,'USERID','PW'); sub connect { my $host = $_[0]; my $user = $_[1]; my $pw = $_[2]; my $file = "aFile.txt"; open(FILE, '>./myFile.txt') or die "Can't create myFile.txt: $!"; print FILE "HELLO"; my $ssh2 = Net::SSH2->new(); $ssh2->connect($host); if ($ssh2->auth_password($user, $pw)) { print "\nIN SFTP\n"; $ssh2->scp_get('./test/out/aFile.txt'); print "Error: ", $ssh2->error(); } $ssh2->disconnect(); return $ssh2; } print "HI";

MY RESULTS ARE:::

IN SFTP
Error: -28LIBSSH2_ERROR_SCP_PROTOCOLTimed out waiting for SCP responseHI

Any help would be greatly appreciated

llass61

20071107 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

Replies are listed 'Best First'.
Re: Net::ssh2 timeout
by syphilis (Archbishop) on Nov 06, 2007 at 06:41 UTC
    Hi llass61,

    See 'read.pl' in the 'example' folder that's part of the Net-SSH2 source distro.

    The following, based partly on 'read.pl' and partly on the sample you provided runs fine for me:
    use Net::SSH2; use IO::Scalar; use strict; my $host = "192.168.0.3"; my $handle = IO::Scalar->new;; my $ssh2 = &connect($host,'user','pass'); sub connect { my $host = $_[0]; my $user = $_[1]; my $pw = $_[2]; my $ssh2 = Net::SSH2->new(); $ssh2->connect($host); if ($ssh2->auth_password($user, $pw)) { print "\nIN SFTP\n"; $ssh2->scp_get('./Documents/trig.c', $handle); print "Error: ", $ssh2->error(), "\n"; $handle->seek(0, 0); _read($handle); } $ssh2->disconnect(); return $ssh2; } sub _read { my $handle = shift; while (my $line = <$handle>) { print $line; } }
    Cheers,
    Rob
      I tried again and still got the same error.

      Error: -28LIBSSH2_ERROR_SCP_PROTOCOLTimed out waiting for SCP response

      Is there a way to increase the amount of time it waits for a response? Anyone show me how?

      Thanks!
        Is there a way to increase the amount of time it waits for a response?

        The only reference I can find to "timeout" in the Net::SSH2 documentation is in relation to the poll method. Looking at the test script that's part of the source distro, it seems that $ssh2->poll(0); sets the timeout to indefinite.

        Now, I have no idea what 'poll' actually does, but since it's apparently the only way to set a "timeout", I guess you could try setting it and see what happens. (Good luck :-)

        Other than that, I'd be starting to wonder if there's a problem at the other end with the SSH2 server that they're running.

        Cheers,
        Rob
Re: Net::ssh2 timeout
by apl (Monsignor) on Nov 06, 2007 at 10:54 UTC
    syphilis seems to have answered your problem, so I'd like to toss in a minor nit -- you might want to display a warning if auth_password fails. Otherwise you have a silent error (after you remove the debugging print "\nIN SFTP\n";). That is, you don't signon, you don't get the file, but things clean up nicely without you knowing nothing happened.