From 7444c1e328aa80ddf8bbfb3f25d067de9942cf2e Mon Sep 17 00:00:00 2001 From: Charlie Burnett Date: Mon, 30 Dec 2024 11:24:24 -0600 Subject: [PATCH 1/2] Fix spaces in windows path --- lib/net/scp.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/net/scp.rb b/lib/net/scp.rb index 1bb4333..db1a281 100644 --- a/lib/net/scp.rb +++ b/lib/net/scp.rb @@ -344,7 +344,9 @@ def scp_command(mode, options) def start_command(mode, local, remote, options={}, &callback) session.open_channel do |channel| - if options[:shell] + if options[:windows_path] + command = "#{scp_command(mode, options)} #{remote.gsub('\\', '/')}" + elsif options[:shell] escaped_file = shellescape(remote).gsub(/'/) { |m| "'\\''" } command = "#{options[:shell]} -c '#{scp_command(mode, options)} #{escaped_file}'" else From b65ca6a996698434914aad351246f5a7cc450581 Mon Sep 17 00:00:00 2001 From: Charlie Burnett Date: Mon, 30 Dec 2024 12:05:19 -0600 Subject: [PATCH 2/2] Check for "'" in windows paths with space --- lib/net/scp.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/net/scp.rb b/lib/net/scp.rb index db1a281..68a702f 100644 --- a/lib/net/scp.rb +++ b/lib/net/scp.rb @@ -345,7 +345,11 @@ def start_command(mode, local, remote, options={}, &callback) session.open_channel do |channel| if options[:windows_path] - command = "#{scp_command(mode, options)} #{remote.gsub('\\', '/')}" + escaped_file = remote.gsub(/'/) { |m| '/' } + unless escaped_file.index(' ').nil? || escaped_file.match?(/^'.+'$/) + escaped_file = "'#{escaped_file}'" + end + command = "#{scp_command(mode, options)} #{escaped_file}" elsif options[:shell] escaped_file = shellescape(remote).gsub(/'/) { |m| "'\\''" } command = "#{options[:shell]} -c '#{scp_command(mode, options)} #{escaped_file}'"