I've have the following sub in my program
sub sftp_file { my ($file,$destfile,$host,$port,$user,$privpath,$pubpath,$pass) = +@_; my $ssh2 = Net::SSH2->new(); $ssh2->connect( $host,$port ) or $logger->info("Connect failed: $! +\n"); if ( !$ssh2->error ) { $ssh2->auth( username => $user, publickey => $pubpath, private +key => $privpath, password => $pass, passphrase => undef ) or $logger +->info("Authent ication failed: $!\n"); } if ( $ssh2->auth_ok ) { my $sftp = Net::SFTP::Foreign->new( ssh2 => $ssh2, backend => +'Net_SSH2' ); $sftp->error and $logger->info("Unable to establish SFTP conne +ction: $sftp->error\n"); $sftp->put( "$file", "$destfile", best_effort => 1 ) or ( $log +ger->info("Put failed: $sftp->error\n") && return ); return 1; } else { return 0; } }
The sub works fine if I call it before I startup and threads. If I call it in a thread I get the following error:
Connect failed: Resource temporarily unavailable
When I turn on tracing of libssh2 and debug I see the following
[libssh2] 0.822042 Transport: session_startup for socket 5 [libssh2] 0.822225 Transport: Sending Banner: SSH-2.0-libssh2_1.8.0 [libssh2] 0.822280 Socket: Sent 23/23 bytes at fe7b1570+0 [libssh2] 0.822334 Socket: Recved 0 bytes banner [libssh2] 0.822366 Failure Event: -13 - Failed getting banner Net::SSH2::DESTROY object 0x3413458 [libssh2] 0.825767 Transport: Freeing session resource [libssh2] 0.825807 Transport: Extra packets left 0 [libssh2] 0.825839 Transport: unable to reset socket's blocking state
Is there work around ?

In reply to Net::SSH2 issue in thread by roperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.