From ec31195d8252470c08372bd7c1b781afadf29838 Mon Sep 17 00:00:00 2001 From: Artsiom Date: Thu, 27 Jul 2017 16:03:28 +0300 Subject: [PATCH 1/3] Add support for windows paths with spaces --- lib/net/scp.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/net/scp.rb b/lib/net/scp.rb index 785a3b4..a20ae67 100644 --- a/lib/net/scp.rb +++ b/lib/net/scp.rb @@ -194,7 +194,7 @@ class SCP include Net::SSH::Loggable include Upload, Download - # Starts up a new SSH connection and instantiates a new SCP session on + # Starts up a new SSH connection and instantiates a new SCP session on # top of it. If a block is given, the SCP session is yielded, and the # SSH session is closed automatically when the block terminates. If no # block is given, the SCP session is returned. @@ -293,7 +293,7 @@ def upload!(local, remote, options={}, &progress) # * :preserve - the atime and mtime of the file should be preserved. # * :verbose - the process should result in verbose output on the server # end (useful for debugging). - # + # # This method will return immediately, returning the Net::SSH::Connection::Channel # object that will support the download. To wait for the download to finish, # you can either call the #wait method on the channel, or otherwise run @@ -343,12 +343,16 @@ def scp_command(mode, options) # (See Net::SCP::Upload and Net::SCP::Download). def start_command(mode, local, remote, options={}, &callback) session.open_channel do |channel| - - if options[:shell] - escaped_file = shellescape(remote).gsub(/'/) { |m| "'\\''" } - command = "#{options[:shell]} -c '#{scp_command(mode, options)} #{escaped_file}'" + + if options[:windows_path] + command = "#{scp_command(mode, options)} \"#{remote}\"" else - command = "#{scp_command(mode, options)} #{shellescape remote}" + if options[:shell] + escaped_file = shellescape(remote).gsub(/'/) { |m| "'\\''" } + command = "#{options[:shell]} -c '#{scp_command(mode, options)} #{escaped_file}'" + else + command = "#{scp_command(mode, options)} #{shellescape remote}" + end end channel.exec(command) do |ch, success| From 0e408d2ca746e01f0b09a9ec7bdc4ebbbfffe08b Mon Sep 17 00:00:00 2001 From: Artsiom Date: Thu, 3 Aug 2017 14:14:50 +0300 Subject: [PATCH 2/3] Convert backslashes to slashes in windows paths --- lib/net/scp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net/scp.rb b/lib/net/scp.rb index a20ae67..d45e1e3 100644 --- a/lib/net/scp.rb +++ b/lib/net/scp.rb @@ -345,7 +345,7 @@ def start_command(mode, local, remote, options={}, &callback) session.open_channel do |channel| if options[:windows_path] - command = "#{scp_command(mode, options)} \"#{remote}\"" + command = "#{scp_command(mode, options)} \"#{remote.gsub('\\', '/')}\"" else if options[:shell] escaped_file = shellescape(remote).gsub(/'/) { |m| "'\\''" } From c92ba076d96a786b65138b30fce7792c0e78a7a0 Mon Sep 17 00:00:00 2001 From: Artsiom Musin Date: Tue, 10 Jul 2018 16:46:59 +0300 Subject: [PATCH 3/3] remove quotes around filename as they mess up the command with latest windows openssh versions --- lib/net/scp.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net/scp.rb b/lib/net/scp.rb index 522fce4..67f9d49 100644 --- a/lib/net/scp.rb +++ b/lib/net/scp.rb @@ -345,7 +345,7 @@ def start_command(mode, local, remote, options={}, &callback) session.open_channel do |channel| if options[:windows_path] - command = "#{scp_command(mode, options)} \"#{remote.gsub('\\', '/')}\"" + command = "#{scp_command(mode, options)} #{remote.gsub('\\', '/')}" else if options[:shell] escaped_file = shellescape(remote).gsub(/'/) { |m| "'\\''" }