Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

debugging Net::Sftp::Foreign using ssh2

by sdetweil (Sexton)
on Dec 12, 2012 at 12:58 UTC ( #1008498=perlquestion: print w/replies, xml ) Need Help??
sdetweil has asked for the wisdom of the Perl Monks concerning the following question:

I have an application that runs on multiple platforms (windows, linux, solaris, aix, hpux). and uses SFTP to send files to our host server.
I needed a 64bit windows version, but the underlying libs for SFTP are not ported to 64bit windows (math::Pari, etc)..
so I rewrote the function to use SFTP:Foreign and use SSH2. all works ok so far.. today I received a trouble report, the ftp send fails, leaving a 0 length file on the server.

I am trying to figure out how to debug this..

use Net::SSH2; use Net::SFTP::Foreign; my $ssh2 = Net::SSH2->new(); $ssh2->debug($debugFlag eq $true ? 1:0); $ssh2->connect($ftpSecureServer) or die "Connect failed!\n"; $ssh2->auth_password($ftpUser, $ftpPW) or die "password auth failed\n"; $ftp = Net::SFTP::Foreign->new(ssh2 => $ssh2, backend => 'Net_SSH2');
from this
$ftp = Net::SFTP::Foreign-> new(host => $ftpSecureServer, backend => 'Net_SSH2', user => $ftpUser, password => $ftpPW);
both use this code to actually send
$ftp->put( $zipFileName, $ftpDir."/" . $newname ); if ( !$@ ) { printl("Transmission complete..\n"); $rc = $true; } else { printl("file $zipFileName upload failed, try later\n"); }
the 32 SFTP version does
$ftp->put( $zipFileName, $newname ); if ( !$error ) { # etc
setting SSH2 debug gets me the gory details, but nothing really useful
libssh2_channel_open_ex(ss->session, pv_channel_type, len_channel_type +, window_s ize, packet_size, ((void *)0) , 0 ) -> 0x47dc418 Net::SSH2::Channel::read(size = 4, ext = 0) - read 4 bytes - read 4 total Net::SSH2::Channel::read(size = 5, ext = 0) - read 5 bytes - read 5 total
anyone have any suggestions?

Replies are listed 'Best First'.
Re: debugging Net::Sftp::Foreign using ssh2
by salva (Abbot) on Dec 12, 2012 at 14:56 UTC
    The way to check for errors on Net::SFTP::Foreign is calling the error method:
    $sftp->put(...); if ($sftp->error) { ... };
    Or alternatively, use the autodie feature:
    my $sftp = Net::SFTP::Foreign->new(..., autodie => 1);
    In order to activate debugging set...
    $Net::SFTP::Foreign::debug = -1;

    Also, note that libssh2/Net::SSH2 are somewhat buggy. Ensure that at least you are using the latest versions.

      >In order to activate debugging set... $Net::SFTP::Foreign::debug = -1; where did you find that? there are all kinds of workarounds here, but nothing that straight forward.. thank you.. adding the debug, it does not fail..typical!.. but the debug output is good..

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1008498]
Front-paged by ww
[Lady_Aleena]: Corion, I knew that, I was just giving Discipulus a hard time.
choroba likes the story at the end of the node
[choroba]: reminds me of the days at the bank
[Corion]: Lady_Aleena: Hehe ;-D
[Lady_Aleena]: Corion, it was PerlMonks who kept pushing me to get Linux, so now I know some of the commands to use in word play.
[Corion]: Lady_Aleena: :-D

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2017-04-26 08:28 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (471 votes). Check out past polls.