Subject: Error Handling with Net::SSH2

Error Handling with Net::SSH2

From: David E. Wheeler <>
Date: Mon, 12 Jul 2010 11:11:59 -0700


I've updated the code in Bricolage that uses Net::SSH2 (the Perl interface to libssh2) to distribute files to servers. The update now properly checks error conditions. As a result, there are now more errors to deal with. So I'm trying to figure out the cause of them. The complete code is here:

The first error is from this excerpt from line 290:

    my $ret = $ssh2->auth(
        ($server->get_login ? (
            username => $server->get_login,
            password => $server->get_password,
        ) : ()),
            publickey => SFTP_PUBLIC_KEY_FILE,
            privatekey => SFTP_PRIVATE_KEY_FILE,
        ) : ()),
        error => "Error authenticating to '$hn' via SSH2",
        payload => join ' ', $ssh2->error,
    ) unless $ret && $ssh2->auth_ok;

The error, thrown in that last statement, is:

  -37 LIBSSH2_ERROR_EAGAIN Would block requesting userauth list

I think that there might be both a login and a SFTP_PUBLIC_KEY_FILE value. Is there really any harm in passing both the username/password and publickey/privatekey params? Is that in fact the source of the error? Should this error simply be ignored?

The second error comes from this statement at line 177:

    $sftp->rename($temp_dest, $dest_file) or throw_gen(
        error => "Error renaming '$temp_dest' to '$dest_file' on '$hn'",
        payload => join ' ', $sftp->error

The error is:


Which seems to be because the server to which we've connected has generated some sort of error. But beyond that, I'm mystified. The call to scp_put() appears to have worked at line 172, so I'm not sure why it would complain about a rename(). Is there any way to get more information about the underlying error?



Received on 2010-07-12