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

Dear wise Monks,

I am trying to program a little call routine for scp. I've found Net::SCP::Expect . It seems Net::SCP is not mighty enough to handle my needs. First question, does someone have another package which might be more easy or better?

As we all know, we can send a SCP through a system call like

scp -2 -q -C -i identity_file -P port -oBatchMode=yes -oStrictHostKeyChecking=no $localfilename $login\@$server:$remotefilename

The request to me now is to give a routine with parameters which does the call "in perl".

I think I have understood some things right:

  1. -q is automatically set
  2. -C is set through the OTION compress, but how do I have to write it? is it: compress=>1 ?
  3. -2 is set by protocol, so if I want to request protocol 2 it is written that? protocol=>2
  4. my server is passed that way? host=>$server
  5. user=>$login

Two other things I am asking myself how to do. I have given the options:

How can I give them to the new method?

Thanks in advance and best regards, Thomas

Replies are listed 'Best First'.
Re: using scp package and options
by salva (Canon) on Feb 03, 2015 at 16:37 UTC
    My completely biased advise is that you should go with Net::OpenSSH instead:
    use Net::OpenSSH; $ssh = Net::OpenSSH->new($server, port => $port, batch_mode => 1, user => $user, key_path => $identity_file, master_opts => ['-C', '-oStrictHostKeyCheckin +g=no']); $ssh->scp_put($local_file, $remote_file) or die "scp_put failed: ".$ss +h->error;

      Thank you for your answer.

      If you would mind helping me again please, I would appreciate your answers to some extra questions. But before, yes I did read the documentation under CPAN.org .

      1. It has to be "($server," instead of "(host => $server," ? I only want to be sure in this.
      2. Is it right, that the batchmode option is automatically set?
      3. Is it so that the protocol to set to 2 is not necessary?
      4. Doesnt $ssh have to closed like $ssh->quit or that way?

      Thanks in advance, Have a nice day, Thomas

        1: Both ways are valid:
        $s1 = Net::OpenSSH->new($host, ...); $s2 = Net::OpenSSH->new(host => $host, ...);

        2: No, by default Net::OpenSSH let's ssh ask you questions. If you want batch mode you have to state it:

        $s = Net::OpenSSH->new($host, batch_mode => 1, ...)

        3: Yes because Net::OpenSSH only works with version 2 of the protocol. SSH v1 is not supported.

        4: The connection is closed automatically when the object goes out of scope. You can close it explicitly if you want:

        $s->disconnect;

        update: disconnect method is only available in the latest development versions.

        Also, if you need to connect using SSH v1, my other module Net::SSH::Any does support it.