Skip to content

Commit

Permalink
Fix for bug in download command handler for source and dest path
Browse files Browse the repository at this point in the history
  • Loading branch information
arale61 committed Apr 2, 2023
1 parent 63ec738 commit de6a507
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions evil-winrm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def download_dir(remote_path, local_path, chunk_size, first)

FileUtils.mkdir_p(local_path) unless File.directory?(local_path)
command = "Get-ChildItem #{remote_path} | Select-Object Name"

@connection.shell(:powershell) { |e| e.run(command) }.stdout.strip.split(/\n/).drop(2).each do |file|
download(File.join(remote_file_path.to_s, file.strip), File.join(local_path, file.strip), chunk_size, false)
end
Expand Down Expand Up @@ -622,7 +623,7 @@ def main
source_s = paths.pop
elsif paths.length == 1
source_s = paths.pop
dest_s = "#{pwd}\\#{extract_filename(dest_s)}"
dest_s = "#{pwd}\\#{extract_filename(source_s)}"
end
if extract_filename(source_s).empty? || extract_filename(source_s).include?("*")
print_message("A filename must be specified!", TYPE_ERROR, true, $logger)
Expand Down Expand Up @@ -657,25 +658,37 @@ def main
if paths.length == 2
dest = paths.pop
source = paths.pop
elsif paths.length == 1
else
source = paths.pop
dest = ""
end

if source.match(/^\.[\\\/]/)
source = source.gsub(/^\./, "")
end
unless source.match(/^[a-zA-Z]:[\\\/]/) then
source = pwd + '\\' + source.gsub(/^[\\\/]/, '')
end

if dest.empty?
source_expr_i = source.index(/(\*\.|\*\*|\.\*|\*)/) || -1
if source_expr_i < 0
if source_expr_i <= 0
dest = "#{extract_filename(source)}"
else
index_last_folder = source.rindex(/[\\\/]/, source_expr_i)
dest = "#{extract_filename(source[0..index_last_folder])}"
end
end

if dest.match?(/(\.\/|\/)$/)
if dest.match?(/^(\.[\\\/]|\.)$/)
dest = "#{extract_filename(source)}"
end

if extract_filename(source).empty?
print_message("A filename or folder must be specified!", TYPE_ERROR, true, $logger)
else
size = filesize(shell, source)
source = source.gsub("/", "\\") if Gem.win_platform?
dest = dest.gsub("\\", "/") unless Gem.win_platform?
print_message("Downloading #{source} to #{dest}", TYPE_INFO, true, $logger)
downloaded = file_manager.download(source, dest, size: size) do |index, size|
Expand Down

0 comments on commit de6a507

Please sign in to comment.