http://qs321.pair.com?node_id=1232405

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

Hey there,

I have a perl script that is taking some files off a server - renaming some files - and putting them on a remote ftp server.

This script originally written by someone else, I'm just trying to make it work again after some updates.

Currently, my script fails with this error.

No matching cipher found: client 3des-cbc,blowfish-cbc,arcfour server aes256-ctr,aes192-ctr,aes128-ctr at /usr/local/share/perl5/Net/SSH/Perl/SSH2.pm line 92.

I have tried modifying the ~/.ssh/config file with different Ciphers but I cannot seem to make that work no matter what I put in there.

I was told to use Net::SFTP::Foreign instead of Net::SFTP (line 15)

Whenever I use this instead my script dies with "Not a HASH reference at /root/backup/backswitch.pl line 20."

Is there a way to modify that line to make it work with the newer SFTP::Foreign - I'm not against doing it either way as long as it works.

Thanks for your help I greatly appreciate it.

#!/usr/bin/perl -w require 5.002; use Net::SFTP; use Net::FTP; use Net::SFTP::Foreign; use warnings; my ($i,$all,%arg,$host,$path); %arg = ( user => "username", password=> "password", ); $host="1.1.1.1"; my $sftp = Net::SFTP::Foreign->new($host,%arg); my $ftp = Net::FTP->new("1.1.1.1",Port=>21) or die "Cannot connect to +1.1.1.1"; $ftp->login("username","password"); foreach $i ($sftp->ls(".")){ $fname=$i->{filename}; if ($fname=~ m/.pri$/){ $rname="/home/location/$fname"; if (-e $rname){ }else{ push @fields,$fname ; } } } foreach $i( @fields){ $sftp->get($i,"/home/msbill1/$i"); $ftp->put("/home/msbill1/$i","/tocustomer/$i"); ($t,undef)=split '.pri',$i; $t=$t.".scd"; # print "$t \n"; $sftp->do_rename($i,$t); }

Replies are listed 'Best First'.
Re: Modifying Script From Net::SFTP to Net::SFTP::Foreign
by salva (Canon) on Apr 10, 2019 at 21:07 UTC
    As part of the Net::SFTP::Foreign distribution you will find the adapter module Net::SFTP::Foreign::Compat which exposes the same API as Net::SFTP.

    Just add the following line at the beginning of your script:

    use Net::SFTP::Foreign::Compat ':supplant';

    ... and all the calls to Net::SFTP would be diverted to Net::SFTP::Foreign.

    There may be some edge cases where the behaviors of both modules differ, but not in the most common cases. At least I have not received bug reports for the adapter module for a long time... though, maybe that is because it has fallen out of popularity, who knows!

Re: Modifying Script From Net::SFTP to Net::SFTP::Foreign
by atcroft (Abbot) on Apr 10, 2019 at 16:07 UTC

    Not a solution (sorry), but an observation-that error sounds oddly familiar. Did the system being contacted update their version of OpenSSH from 5.x/6.x to 7.x? And what is the version of your Net::SFTP and Net::SSH::Perl? OpenSSH 7.0/7.0p1 was released 2015-08-11, with Net::SFTP and Net::SSH::Perl versions 1.39 and beyond being released after that date. My thought is that perhaps a newer version of those modules might also be an option (if you can't get a satisfactory answer to your primary question, but make sure to test first!).

    Hope that helps.

    Update: 2019-04-10
    s/Net::SFTP/Net::SFTP and Net::SSH::Perl/g
    s/that module/those modules/g

      The system being contacted did do a lot of updates - yes I think you're spot on. I believe I have the latest of those two modules - I tried to do a yum udpate on both of them and it tells me it is the latest version.
Re: Modifying Script From Net::SFTP to Net::SFTP::Foreign
by poj (Abbot) on Apr 10, 2019 at 15:53 UTC

    Run this script and post the result to show module versions

    #!/usr/bin/perl use strict; use Net::SFTP; use Net::SFTP::Foreign; use Net::SSH::Perl; printf "%s %s\n",$^O,$^V; printf "Net::SFTP %s\n",$Net::SFTP::VERSION; printf "Net::SFTP::Foreign %s\n",$Net::SFTP::Foreign::VERSION; printf "Net::SSH::Perl %s\n",$Net::SSH::Perl::VERSION;
    "Not a HASH reference at /root/backup/backswitch.pl line 20."

    Which is line 20 ?

    poj

      linux v5.10.1

      Net::SFTP 0.10

      Net::SFTP::Foreign 1.81

      Net::SSH::Perl 1.37

Re: Modifying Script From Net::SFTP to Net::SFTP::Foreign
by hippo (Bishop) on Apr 10, 2019 at 18:33 UTC
    Not a HASH reference at /root/backup/backswitch.pl line 20.
    foreach $i ($sftp->ls(".")){ $fname=$i->{filename};

    As per the documentation, $sftp->ls returns a reference to a list, not a list.

      yes, ls returns a reference in order to be able to signal errors. The usual idiom for using it is as follows:
      my $ls = $sftp->ls(...) or die "ls failed: " . $sftp->error; for my $fn (@$ls) { ... }