Skip to content

Commit d0969f7

Browse files
Add remote_src option to scp_put
If remote_src is true it indicates you wish to scp from the remote machine. This facilitates server to server copies.
1 parent 64c5123 commit d0969f7

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

lib/Net/OpenSSH.pm

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,9 +2124,17 @@ sub _scp_put_args {
21242124
$prefix = "$self->{_user}\@$prefix" if defined $self->{_user};
21252125

21262126
my $remote_shell = delete $opts{remote_shell};
2127-
my $target = $prefix . ':' . ( @_ > 1
2128-
? $self->_quote_args({quote_args => 1, remote_shell => $remote_shell}, pop(@_))
2129-
: '');
2127+
my $remote_src = delete $opts{remote_src};
2128+
2129+
# if remote_src is set then we are 'put'ing from the remote machine
2130+
# so we can't assume the target will be the remote machine
2131+
my($target);
2132+
if (! $remote_src) {
2133+
$target = $prefix . ':';
2134+
}
2135+
$target .= ( @_ > 1
2136+
? $self->_quote_args({quote_args => 1, remote_shell => $remote_shell}, pop(@_))
2137+
: '');
21302138

21312139
my @src = @_;
21322140
if ($glob) {
@@ -2138,7 +2146,11 @@ sub _scp_put_args {
21382146
return undef;
21392147
}
21402148
}
2141-
$_ = "./$_" for grep m|^[^/]*:|, @src;
2149+
if ($remote_src) {
2150+
map { $_ = $prefix . ':' . $_ } @src;
2151+
} else {
2152+
$_ = "./$_" for grep m|^[^/]*:|, @src;
2153+
}
21422154

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

0 commit comments

Comments
 (0)