Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow uploading files even when permissions cannot be set. #1471

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/Rex/Interface/Fs/OpenSSH.pm
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,32 @@ sub stat {
return %ret;
}

=pod

=head3 OpenSSH->upload($source, $target)

Uploads an item from source to target.

If sudo is enabled for the connection will set permissions etc too.
Otherwise will only attempt to set permissions, and continue successfully
if not.

=cut

sub upload {
my ( $self, $source, $target ) = @_;

Rex::Commands::profiler()->start("upload: $source -> $target");

my $sftp = Rex::get_sftp();
unless ( $sftp->put( $source, $target ) ) {

# If we are not sudo, we need to fall back to best effort on
# file upload. The %best_effort hash will evaluate be expanded
# to best_effort => 1 if and and only if is_sudo returns false.

my %best_effort = ();
$best_effort{best_effort} = 1 unless Rex::is_sudo();
unless ( $sftp->put( $source, $target, %best_effort) ) {
Rex::Logger::debug("upload: $target is not writable");

Rex::Commands::profiler()->end("upload: $source -> $target");
Expand Down