Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow for upload to use the filename of the local file by default and…

… test
  • Loading branch information...
commit 1126977fcf61dd75745190e56118691bb106c0de 1 parent 09f1b79
@czarneckid czarneckid authored
Showing with 16 additions and 2 deletions.
  1. +2 −2 lib/net/sftp/session.rb
  2. +14 −0 test/test_upload.rb
View
4 lib/net/sftp/session.rb
@@ -94,12 +94,12 @@ def initialize(session, &block)
#
# uploader = sftp.upload("/local/path", "/remote/path")
# uploader.wait
- def upload(local, remote, options={}, &block)
+ def upload(local, remote = File.basename(local), options={}, &block)
Operations::Upload.new(self, local, remote, options, &block)
end
# Identical to #upload, but blocks until the upload is complete.
- def upload!(local, remote, options={}, &block)
+ def upload!(local, remote = File.basename(local), options={}, &block)
upload(local, remote, options, &block).wait
end
View
14 test/test_upload.rb
@@ -10,6 +10,20 @@ def test_upload_file_should_send_file_contents
assert_scripted_command { sftp.upload("/path/to/local", "/path/to/remote") }
end
+ def test_upload_file_without_remote_uses_filename_of_local_file
+ expect_file_transfer("/path/to/local", "local", "here are the contents")
+
+ assert_scripted_command do
+ sftp.upload("/path/to/local") { |*args| record_progress(args) }
+ end
+
+ assert_progress_reported_open(:remote => "local")
+ assert_progress_reported_put(0, "here are the contents", :remote => "local")
+ assert_progress_reported_close(:remote => "local")
+ assert_progress_reported_finish
+ assert_no_more_reported_events
+ end
+
def test_upload_file_with_progress_should_report_progress
expect_file_transfer("/path/to/local", "/path/to/remote", "here are the contents")
Please sign in to comment.
Something went wrong with that request. Please try again.