in reply to Re: scp recommendations
in thread scp recommendations

system("scp", "--", $from, $to)
unless you want to spend time converting $from and $to into shell literals.

Replies are listed 'Best First'.
Re^3: scp recommendations
by salva (Canon) on Aug 01, 2010 at 19:19 UTC
    That's not enough either as scp in order to run another scp as its slave in the remote side, calls ssh as...
    system('ssh', 'scp', '-t', @args)
    But the SSH protocol accepts only a single command string, ssh joins everything in one line and the command arrives at the remote machine as...
    system("scp -t @args")
    And it is called through the shell. That's why @args has to be escaped in order to avoid the remote shell doing unexpected things.
      # No good on Windows sub text_to_shell_lit { my ($s) = @_; $s =~ s/'/'\\''/g; return "'$s'"; }
      my $cmd = join ' ', map text_to_shell_lit($_), scp => '-t', @args; system(ssh => $cmd);
        well, actually it should be...
        my $quoted_to = text_to_shell_lit($to); system 'scp', '--', $from, "${host}:$quoted_to";
        or
        my $quoted_from = text_to_shell_lit($from); system 'scp', '--', "${host}:$quoted_from", $to;