Skip to content

Commit a9a8064

Browse files
committed
Merge pull request #9 from czarneckid/master
Allow for upload to use the filename of the local file by default and test
2 parents 09f1b79 + 1126977 commit a9a8064

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/net/sftp/session.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ def initialize(session, &block)
9494
#
9595
# uploader = sftp.upload("/local/path", "/remote/path")
9696
# uploader.wait
97-
def upload(local, remote, options={}, &block)
97+
def upload(local, remote = File.basename(local), options={}, &block)
9898
Operations::Upload.new(self, local, remote, options, &block)
9999
end
100100

101101
# Identical to #upload, but blocks until the upload is complete.
102-
def upload!(local, remote, options={}, &block)
102+
def upload!(local, remote = File.basename(local), options={}, &block)
103103
upload(local, remote, options, &block).wait
104104
end
105105

test/test_upload.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ def test_upload_file_should_send_file_contents
1010
assert_scripted_command { sftp.upload("/path/to/local", "/path/to/remote") }
1111
end
1212

13+
def test_upload_file_without_remote_uses_filename_of_local_file
14+
expect_file_transfer("/path/to/local", "local", "here are the contents")
15+
16+
assert_scripted_command do
17+
sftp.upload("/path/to/local") { |*args| record_progress(args) }
18+
end
19+
20+
assert_progress_reported_open(:remote => "local")
21+
assert_progress_reported_put(0, "here are the contents", :remote => "local")
22+
assert_progress_reported_close(:remote => "local")
23+
assert_progress_reported_finish
24+
assert_no_more_reported_events
25+
end
26+
1327
def test_upload_file_with_progress_should_report_progress
1428
expect_file_transfer("/path/to/local", "/path/to/remote", "here are the contents")
1529

0 commit comments

Comments
 (0)