<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,8 @@
+=== (unreleased)
+
+* Escape spaces in file names on remote server [Jamis Buck]
+
+
 === 1.0.1 / 29 May 2008
 
 * Make sure downloads open the file in binary mode to appease Windows [Jamis Buck]</diff>
      <filename>CHANGELOG.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -337,7 +337,7 @@ module Net
       # (See Net::SCP::Upload and Net::SCP::Download).
       def start_command(mode, local, remote, options={}, &amp;callback)
         session.open_channel do |channel|
-          command = &quot;#{scp_command(mode, options)} #{remote}&quot;
+          command = &quot;#{scp_command(mode, options)} #{sanitize_file_name(remote)}&quot;
           channel.exec(command) do |ch, success|
             if success
               channel[:local   ] = local
@@ -398,6 +398,10 @@ module Net
       def progress_callback(channel, name, sent, total)
         channel[:callback].call(channel, name, sent, total) if channel[:callback]
       end
+
+      def sanitize_file_name(file_name)
+        file_name.gsub(/[ ]/) { |m| &quot;\\#{m}&quot; }
+      end
   end
 end
 
@@ -407,4 +411,4 @@ class Net::SSH::Connection::Session
   def scp
     @scp ||= Net::SCP.new(self)
   end
-end
\ No newline at end of file
+end</diff>
      <filename>lib/net/scp.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,6 +12,20 @@ class TestDownload &lt; Net::SCP::TestCase
     assert_equal &quot;a&quot; * 1234, file.io.string
   end
 
+  def test_download_file_with_spaces_in_name_should_escape_remote_file_name
+    file = prepare_file(&quot;/path/to/local file.txt&quot;, &quot;&quot;)
+
+    expect_scp_session &quot;-f /path/to/remote\\ file.txt&quot; do |channel|
+      channel.sends_ok
+      channel.gets_data &quot;C0666 0 local file.txt\n&quot;
+      channel.sends_ok
+      channel.gets_ok
+      channel.sends_ok
+    end
+
+    assert_scripted { scp.download!(&quot;/path/to/remote file.txt&quot;, &quot;/path/to/local file.txt&quot;) }
+  end
+
   def test_download_with_preserve_should_send_times
     file = prepare_file(&quot;/path/to/local.txt&quot;, &quot;a&quot; * 1234, 0644, Time.at(1234567890, 123456), Time.at(12121212, 232323))
 </diff>
      <filename>test/test_download.rb</filename>
    </modified>
    <modified>
      <diff>@@ -16,6 +16,20 @@ class TestUpload &lt; Net::SCP::TestCase
     assert_scripted { scp.upload!(&quot;/path/to/local.txt&quot;, &quot;/path/to/remote.txt&quot;) }
   end
 
+  def test_upload_file_with_spaces_in_name_should_escape_remote_file_name
+    prepare_file(&quot;/path/to/local file.txt&quot;, &quot;&quot;)
+
+    expect_scp_session &quot;-t /path/to/remote\\ file.txt&quot; do |channel|
+      channel.gets_ok
+      channel.sends_data &quot;C0666 0 local file.txt\n&quot;
+      channel.gets_ok
+      channel.sends_ok
+      channel.gets_ok
+    end
+
+    assert_scripted { scp.upload!(&quot;/path/to/local file.txt&quot;, &quot;/path/to/remote file.txt&quot;) }
+  end
+
   def test_upload_file_with_preserve_should_send_times
     prepare_file(&quot;/path/to/local.txt&quot;, &quot;a&quot; * 1234, 0666, Time.at(1234567890, 123456), Time.at(1234543210, 345678))
 </diff>
      <filename>test/test_upload.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ab6644b2b0d2cdd29ea766f9432701bd8fcb10ec</id>
    </parent>
  </parents>
  <author>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </author>
  <url>http://github.com/jamis/net-scp/commit/19c77f3b3fd7ffd4806272d193dca44d5d25318c</url>
  <id>19c77f3b3fd7ffd4806272d193dca44d5d25318c</id>
  <committed-date>2009-02-02T20:17:51-08:00</committed-date>
  <authored-date>2009-02-02T20:17:51-08:00</authored-date>
  <message>make sure spaces in remote file names are escaped</message>
  <tree>926788994cb2c605890db25f673ac3dfa004b7b4</tree>
  <committer>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </committer>
</commit>
