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

I am trying to change all existing Perl scripts that use FTP to use SFTP. I've been trying to install Net::SFTP, and Net::SSH::Perl. I've been searching, and finding others that have tried to do this. And, just as others, I am having problems installing.

I'm wondering if I can go about it differently. The version of Perl we are running is v5.6.1, for sun4-solaris. On www.perl.com, it seems that the latest stable version of Perl is 5.5.8.

The version we are using 'has' Net::FTP included in the installation. At least, this I absolutely know: we installed Perl 5.6.1, and did not do anything else, and I wrote a perl script that has 'use Net::FTP' at the top of the program, and, by George, it works.

So, does the latest version of Perl - 5.5.8 - include the SFTP protocol, natively, with no other installation or futzing around?

Or ... has anyone any other suggestions on how to do this installation?
  • Comment on Latest version of Perl - includes SFTP?

Replies are listed 'Best First'.
Re: Latest version of Perl - includes SFTP?
by zentara (Cardinal) on Apr 26, 2007 at 17:45 UTC
Re: Latest version of Perl - includes SFTP?
by Limbic~Region (Chancellor) on Apr 26, 2007 at 18:09 UTC
    jhs3,
    If you want to know what modules are part of the core, then use Module::CoreList. In addition to those modules, certain distributions include additional modules such as ActiveState Perl on Win32.

    With regards to installing modules, there are far too many links for me to write in this small margin. You may want to look into CPAN, CPANPLUS, apt-get, PPM, etc.

    Cheers - L~R

Re: Latest version of Perl - includes SFTP?
by salva (Canon) on Apr 26, 2007 at 17:28 UTC
    try (the development version of) Net::SFTP::Foreign!

    It doesn't require any other module, just the SSH client installed on your systems.

Re: Latest version of Perl - includes SFTP?
by shift8 (Novice) on Apr 27, 2007 at 03:39 UTC
    Net::SSH::Perl, Net::SFTP and even Net::SSH2 are very problematic to install and are painfully and, in many cases, unusably slow on modern hardware. i haven't tried Net::SFTP::Foreign, so maybe give that a go like was said.

    then again, there are other ways as well - open() as a pipe w/ pki for auth works, or even Expect :) both assume local ssh install.

    joining ssh-sftp-perl-users@lists.sourceforge.net and reviewing the archives for some of the issues you might run into couldn't hurt ether. good luck!
Re: Latest version of Perl - includes SFTP?
by shigetsu (Hermit) on Apr 26, 2007 at 17:21 UTC

    On www.perl.com, it seems that the latest stable version of Perl is 5.5.8.

    I think you meant 5.8.8.

    So, does the latest version of Perl - 5.5.8

    Likewise.

Re: Latest version of Perl - includes SFTP?
by rahed (Scribe) on Apr 27, 2007 at 18:27 UTC
    As far as I know Net::SFTP and Net::SSH::Perl are not part of the core.
    From my experience installing Net::SSH::Perl is a bit tedious. Install the prerequisite modules beforehand (at least those having Math namespace) thus you avoid possible hurdles with complex dependencies.

    I use Net::SSH::Perl on Solaris OSs without any issues.
      Here's what I had to do to install Net::SSH::Perl in my Windows ActivePerl 5.6.1 environment:

      1. Use PPM3 to set the proper repository and install net-ssh-perl

      ppm> rep add "U of Winnipeg" http://theoryx5.uwinnipeg.ca/ppms/package.xml
      ppm> install net-ssh-perl -force –follow

      2. Get Math-GMP-2.04 from CPAN.org and untar it. Build fails due to missing 'gmp.h' and 'gmp.lib' files, so you have to build 'em.

      3. Get GMP from http://cs.nyu.edu/exact/core/gmp/ and follow instructions to build based on how your version of ActivePerl was built. My ActivePerl 5.6.1 was built using Microsoft VC, with ccflags including '-MD', so I followed the instructions for building GMP using this compiler, changing Project…Settings…C/C++…Project Options to use /MD instead of /ML. The build completes with 0 Erros and 132 Warnings.

      4. Copy the resulting gmp.h and gmp.lib to the untarred Math-GMP-2.04 directory. Then build Math-GMP-2.04 using the standard Makefile.PL...nmake...nmake test...nmake install process.

      5. Edit <perl>/site/lib/Net/SSH/Perl.pm and comment out these lines if you get the "Can't set socket non-blocking" error message:

      # defined($sock->blocking(0))
      # or die "Can't set socket non-blocking: $!";

      Here's a test script you can use:

      use Getopt::Std; use Net::SSH::Perl; &getopts('h:u:p:'); &Usage( ) unless( defined($opt_h) && defined($opt_u) && defined($opt_p +) ); $ssh = Net::SSH::Perl->new( $opt_h, port => 22 ); $ssh->login( $opt_u, $opt_p ); while( 1 ) { print "$opt_h\> "; $cmd = <STDIN>; $cmd =~ s/^\s+|\s+$//g; last if( $cmd eq "" ); ($stdout, $stderr, $exit_code) = $ssh->cmd($cmd); if( $exit_code ) { print $stderr; } else { print $stdout; } } exit( 0 ); sub Usage { print “Usage: $0 -h <host> -u <user> -p <password>\n”; exit( 0 ); } # end of Usage
      HTH,
      Dean Leonard