diff --git a/lib/net/sftp/operations/download.rb b/lib/net/sftp/operations/download.rb index e9490b3..8e7275e 100644 --- a/lib/net/sftp/operations/download.rb +++ b/lib/net/sftp/operations/download.rb @@ -145,6 +145,9 @@ class Download # This will return immediately, and requires that the SSH event loop be # run in order to effect the download. (See #wait.) def initialize(sftp, local, remote, options={}, &progress) + local = local.to_path if local.respond_to?(:to_path) + remote = remote.to_path if remote.respond_to?(:to_path) + @sftp = sftp @local = local @remote = remote diff --git a/lib/net/sftp/operations/upload.rb b/lib/net/sftp/operations/upload.rb index 372c34c..4446f50 100644 --- a/lib/net/sftp/operations/upload.rb +++ b/lib/net/sftp/operations/upload.rb @@ -141,6 +141,9 @@ class Upload # This will return immediately, and requires that the SSH event loop be # run in order to effect the upload. (See #wait.) def initialize(sftp, local, remote, options={}, &progress) #:nodoc: + local = local.to_path if local.respond_to?(:to_path) + remote = remote.to_path if remote.respond_to?(:to_path) + @sftp = sftp @local = local @remote = remote diff --git a/test/common.rb b/test/common.rb index af805bb..b83b453 100644 --- a/test/common.rb +++ b/test/common.rb @@ -1,6 +1,7 @@ require 'test/unit' require 'mocha/setup' require 'stringio' +require 'pathname' begin require 'net/ssh' diff --git a/test/test_download.rb b/test/test_download.rb index d9582b6..eb3e6f3 100644 --- a/test/test_download.rb +++ b/test/test_download.rb @@ -35,6 +35,20 @@ def test_download_file_should_transfer_remote_to_local_in_spite_of_fragmentation assert_equal text, file.string end + def test_download_file_should_handle_Pathname + local = Pathname.new("/path/to/local").freeze + remote = Pathname.new("/path/to/remote").freeze + text = "this is some text\n" + + expect_file_transfer(remote.to_s, text) + + file = StringIO.new + File.stubs(:open).with(local.to_s, "wb").returns(file) + + assert_scripted_command { sftp.download(remote, local) } + assert_equal text, file.string + end + def test_download_large_file_should_transfer_remote_to_local local = "/path/to/local" remote = "/path/to/remote" @@ -286,4 +300,4 @@ def prepare_directory_tree_download(local, remote) [file1, file2] end -end \ No newline at end of file +end diff --git a/test/test_upload.rb b/test/test_upload.rb index af52519..c9c9d95 100644 --- a/test/test_upload.rb +++ b/test/test_upload.rb @@ -10,6 +10,13 @@ def test_upload_file_should_send_file_contents assert_scripted_command { sftp.upload("/path/to/local", "/path/to/remote") } end + def test_upload_file_should_handle_Pathname + local = Pathname.new("/path/to/local").freeze + remote = Pathname.new("/path/to/remote").freeze + expect_file_transfer(local.to_s, remote.to_s, "here are the contents") + assert_scripted_command { sftp.upload(local, remote) } + end + def test_upload_file_without_remote_uses_filename_of_local_file expect_file_transfer("/path/to/local", "local", "here are the contents")