Skip to content

Commit

Permalink
Add remote_src option to scp_put
Browse files Browse the repository at this point in the history
If remote_src is true it indicates you wish to scp from the remote
machine. This facilitates server to server copies.
  • Loading branch information
cqexbesd authored and andrew-stevenson-sociomantic committed Jul 9, 2015
1 parent 64c5123 commit d0969f7
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions lib/Net/OpenSSH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2124,9 +2124,17 @@ sub _scp_put_args {
$prefix = "$self->{_user}\@$prefix" if defined $self->{_user};

my $remote_shell = delete $opts{remote_shell};
my $target = $prefix . ':' . ( @_ > 1
? $self->_quote_args({quote_args => 1, remote_shell => $remote_shell}, pop(@_))
: '');
my $remote_src = delete $opts{remote_src};

# if remote_src is set then we are 'put'ing from the remote machine
# so we can't assume the target will be the remote machine
my($target);
if (! $remote_src) {
$target = $prefix . ':';
}
$target .= ( @_ > 1
? $self->_quote_args({quote_args => 1, remote_shell => $remote_shell}, pop(@_))
: '');

my @src = @_;
if ($glob) {
Expand All @@ -2138,7 +2146,11 @@ sub _scp_put_args {
return undef;
}
}
$_ = "./$_" for grep m|^[^/]*:|, @src;
if ($remote_src) {
map { $_ = $prefix . ':' . $_ } @src;
} else {
$_ = "./$_" for grep m|^[^/]*:|, @src;
}

($self, \%opts, $target, @src);
}
Expand Down Expand Up @@ -3503,6 +3515,15 @@ capture of the output of the C<scp> program.
Note that C<scp> will not generate progress reports unless its stdout
stream is attached to a tty.
=item remote_src => 0
scp_put only. Indicates that the src argument is located on the remote host
and the scp is initiated from there. Ordinarily you will specify a target
string beginning with 'host:' to perform a server to server copy. For example,
to copy a file from the remote system to a machine called "host2":
$ssh->scp_put({'remote_src' => 1 }, 'example.txt', 'host2:new_example.txt');
=item ssh_opts => \@opts
List of extra options for the C<ssh> command.
Expand Down

0 comments on commit d0969f7

Please sign in to comment.