in reply to Net::SFTP using ssh_args woes

"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.

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

    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.

        I stand corrected, you are right, but due to the odd behaviour of SFTP (see for example PM search "Net::SFTP"), I switched back to the plain old Net:FTP (for the "employer" didn't care too much about it anyway ;)

        Your coding seems valid, yet I made a mistake of believing "StrictHostKeyChecking no" (as found in `man ssh_config`) would work with Net::SSH::Perl, but it doesn't, so basically, the "ssh_args" flag is useless in my case anyway ;)

        --
        b10m