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

Dear Monks o' Knowledge,

I'm currently messing with Net::SFTP and stumbled across something I don't quite get. I would value your opinions on this.

Because this server runs Apache as user nobody, I would like to disable the StrictHostKeyChecking (read: write to ~/.ssh/known_hosts) for "nobody" is set up to use "$HOME = /".

So far so good! I thought when I saw this in the PODs:


perldoc Net::SFTP

USAGE
Net::SFTP->new($host, %args)
%args can contain:

perldoc Net::SSH::Perl

BASIC USAGE

Usage of Net::SSH::Perl is very simple.
Net::SSH::Perl->new($host, %params)

new accepts the following named parameters in %params:
[snip]

Now how would I tell %args in Net::SFTP->new($host, %args) to usethis options => "StrictHostKeyChecking no"?

I've tried things like the following to no avail:

my %args = (user => $user, password => $pass, debug => 1, ssh_args => (options => "StrictHostKeyChecking no") ); my $sftp = Net::SFTP->new($host, %args)

Update: Basically, my question is: what is meant with "a reference to a list of named arguments"?

--
b10m

Replies are listed 'Best First'.
Re: Net::SFTP using ssh_args woes
by neuroball (Pilgrim) on Jan 09, 2004 at 22:25 UTC

    "a reference fto a list of named arguments" is a reference to a hash.

    Example:

    my %ssh_options = ( StrictHostKeyChecking => "no" ); my %args = ( username => $user, password => $pass, debug => 1, ssh_args => (options => \%ssh_options) ); my $sftp = Net::SFTP->new($host, %args)

    Normally you should be able to fold this in, as so:

    my %args = ( username => $user, password => $pass, debug => 1, ssh_args => (options => { StrictHostKeyChecking => "no"} ) );

    Hope that helps...

    /oliver/

    Update: added my before %ssh_options.

      Thanks for your suggestion, neuroball. After reading the POD for the umpteenth time, I noticed that I shouldn't use the "ssh_args" specifically. This code (see below) works great :)

      my %ssh_options = (options => "StrictHostKeyChecking no"); my %login = (user => $user, password => $pass, debug => 1, \%ssh_options );
      --
      b10m
        Do you use login like: $sftp = Net::SFTP::->new($host, %login)? I haven't ever used Net::SFTP, but from a quick glace at the source, it looks like ssh_args => is supposed to be there and is supposed to be followed by an ref to an array containing extra parameters to put in the call to Net::SSH::Perl::->new. It's hard to see how what you have would work:
        sub new { my $class = shift; my $sftp = bless { }, $class; $sftp->{host} = shift; $sftp->init(@_); } sub init { my $sftp = shift; my %param = @_; $sftp->{debug} = delete $param{debug}; $param{ssh_args} ||= []; $sftp->{_msg_id} = 0; my $ssh = Net::SSH::Perl->new($sftp->{host}, protocol => 2, debug => $sftp->{debug}, @{ $param{ssh_args} }); ...
        with no further use of @_ in init(). It looks like you want something like (completely untested):
        $sftp = Net::SFTP::->new($host, user => $username, password => $password, ssh_args => [ options => [ "StrickHostKeyChecking no" ] ] );
        Which is basically what the doc says, except that both modules say reference to a list where they mean reference to an array.