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

Hi – I just ported a perl script that uses Net-SFTP, over to another box that did not have Net-SFTP installed. After struggling with the dependencies, I installed Net-SFTP-Foreign-1.77 and IO-Tty-1.12 and modified my script. It runs now (and I'm delighted by how compatible all the methods are).

Is there a known issue with Net-SFTP-Foreign not reading the /etc/hosts file, to resolve host names? I have this line of code in my script:

my $sftp = Net::SFTP::Foreign->new(user => $remote_user, host => $remote_host, password => $remote_pswd);

When variable $remote_host is set to the FQDN remote.server.com, script throws this error:

ssh: remote.server.com : Name or service not known

But when the variable is set to the actual IP address, works fine.

I can sftp to remote.server.com (using FQDN) from the Linux command line, and it works fine. (I actually don't even need a hosts file entry to get there – the FQDN is resolved by normal resolution process.) I only see the issue in the script. Is this known behavior? Any parameter I have to set, to help it resolve?

Perl 5.8.8 running on RHEL5.

Thanks,

Jim

Replies are listed 'Best First'.
Re: Net-SFTP-Foreign not reading /etc/hosts file?
by salva (Canon) on Sep 13, 2015 at 17:37 UTC
    Net::SFTP::Foreign (usually) just uses the binary ssh command from your system and, unless you have some really rare configuration, it honors /etc/hosts.

    Anyway, set debugging on for Net::SFTP::Foreign adding the following line at the beginning of your script:

    $Net::SFTP::Foreign::debug = -1;
    ... and then run it and post here the debugging output.

    There should be a line indicating how ssh is called, similar to ...

    #18146 1442165394.00000 _init_transport: ssh cmd: ssh -o NumberOfPassw +ordPrompts=1 -o PreferredAuthentications=keyboard-interactive,passwor +d foo.bar.com -s sftp
    You can also try running that command but without the -s sftp part, at the shell. Does it work? if it doesn't you should start by figuring out why not.

    Finally, if you want compatibility with Net::SFTP, you should go for Net::SFTP::Foreign::Compat instead of Net::SFTP::Foreign.

Re: Net-SFTP-Foreign not reading /etc/hosts file?
by Anonymous Monk on Sep 14, 2015 at 08:23 UTC
    There is a space after remote.server.com in your error message. Could it be the cause of the problem?