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

Hi All Monks,

I have yet one more problem in my backup program (http://migas.kicks-ass.org/index.php?pag=en.myapps&subpag=simplebackup)...

I want to add the sftp option to it, and i'm trying to use the Net::SFTP Module but the module causes the program to stop dead ... has in dead in the water, i can't control the sftp connection/login.

Here is my log of connection...

migas: Reading configuration data /root/.ssh/config
migas: Reading configuration data /etc/ssh_config
migas: Allocated local port 1023.
migas: Connecting to localhost, port 443.
migas: Remote version string: SSH-1.99-OpenSSH_3.9p1
migas: Remote protocol version 1.99, remote software version OpenSSH_3.9p1
migas: Net::SSH::Perl Version 1.30, protocol version 2.0.
migas: No compat match: OpenSSH_3.9p1.
migas: Connection established.
migas: Sent key-exchange init (KEXINIT), wait response.
migas: Algorithms, c->s: 3des-cbc hmac-sha1 none
migas: Algorithms, s->c: 3des-cbc hmac-sha1 none
migas: Entering Diffie-Hellman Group 1 key exchange.
migas: Sent DH public key, waiting for reply.
migas: Received host key, type 'ssh-dss'.
migas: Host 'localhost' is known and matches the host key.
migas: Computing shared secret key.
migas: Verifying server signature.
migas: Waiting for NEWKEYS message.
migas: Enabling incoming encryption/MAC/compression.
migas: Send NEWKEYS, enable outgoing encryption/MAC/compression.
migas: Sending request for user-authentication service.

here the program shell's out
I can't control not even with using eval{ ... }

Here is a sample code
$network_debug_level_real = 1; my $network_server = "localhost"; my $network_server_port = 22; my $network_username = "some_valid_user"; my $network_password = "some_valid_password"; my $network_connection_p; my %ssh_config = ( port => $network_server_port, debug => $network_debug_level_real, ); my %sftp_config = ( user => $network_username, password => $network_password, debug => $network_debug_level_real, ssh_args => \%ssh_config, ); print "before connection\n"; $network_connection = Net::SFTP->new($network_server, %sftp_config ); print "after connection\n";\n"; # This never run's the program shell's + out

SSH and SFTP works using the ssh tools so i know the server is fine.

PS 1: has you can notice the program and the ssh server is running on the same machine.
PS 2: the debug messages appear very slowly.
PS 3: the ssh server gives a timeout error on syslog while waiting for authentication.

Any help would be greateful

Migas - Miguel

Replies are listed 'Best First'.
Re: Net::SFTP connection failure
by zentara (Cardinal) on Sep 20, 2006 at 14:27 UTC
    Well the keywords "slow" and "timeout" ring a bell. The usual answer is install Math::BigInt::GMP or Math::Pari, which speeds up things.

    Also if you can, try Net::SSH2, which works much cleaner. See A little demo for Net::SSH2

    Also, try installing the latest versions of all requirements and modules, it's remarkable how many times that works. :-)


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Hi zentara,

      Thanks a lot for your aswer, but i wonder things can be slow... yes... but why can't i control the flow of the program ???

      The program could be trying to access the ssh server, and at a point the ssh server would give up, but how can one control this ??? i don't want my backup program to "crash" i want him to report something to the user.

      Any way I'm going to check ssh2 again THANKS !

      Is it just me or does anyone feel that the Net::SFTP module is not stable work ??

      Miguel - Miguel
Re: Net::SFTP connection failure
by Khen1950fx (Canon) on Sep 20, 2006 at 15:59 UTC
    Two things: Make sure that Math::Pari is working. Then I would try a specific cipher like blowfish-cbc in your code here:

    ssh_args => \%ssh-config,

    Try this:

     ssh_args => [ cipher => 'blowfish-cbc' ]

      Hi Khen1950fx,

      Thanks i have tried the cipher => 'blowfish-cbc' thing and the encryption changed to blowfish but the program still aborts...
      i still cannot control the login process and (apperantly) the Net::SFTP forces my program to exit... i cannot control it not even using eval{...}

      The only way i made the dam thing work and login was to increase (a lot) the sshd (/etc/ssh/sshd_config) autentication timeout value..., but this is not a solution i cannot expect every user out there to change this value.

      I think that i have all the necessary modules installed i have installed Net::SFTP from cpan (perl -CPAN... etc).


      Migas - Miguel
Re: Net::SFTP connection failure
by Khen1950fx (Canon) on Sep 20, 2006 at 17:04 UTC
      Hello again Khen1950fx,

      Man is this sftp thing hard... i have done in perl ftp ; web dav ; smtp mail... but this encryption thing is hard....
      I would like to allow key authentication, but i also want the user to simply type in a user/password in my backup program (simplebackup) configuration file... so he would not have to have the trouble of creating configuration keys etc...
      For the simplebackup program i want to make life has easy has possible for the end user

      Any way thanks !
      Migas - Miguel