Skip to content

Commit 9421993

Browse files
committed
Merge pull request #12 from Pablo-Merino/master
Added an option to not create the upload directory
2 parents 86c2b04 + 80e842b commit 9421993

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/net/sftp/operations/upload.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ module Net; module SFTP; module Operations
3030
# This will upload "/path/to/directory", it's contents, it's subdirectories,
3131
# and their contents, recursively, to "/path/to/remote" on the remote server.
3232
#
33+
# For uploading a directory without creating it, do
34+
# sftp.upload!("/path/to/directory", "/path/to/remote", :create_dir => false)
35+
#
3336
# If you want to send data to a file on the remote server, but the data is
3437
# in memory, you can pass an IO object and upload it's contents:
3538
#
@@ -157,12 +160,17 @@ def initialize(sftp, local, remote, options={}, &progress) #:nodoc:
157160
@remote_cwd = remote
158161

159162
@active += 1
160-
sftp.mkdir(remote) do |response|
161-
@active -= 1
162-
raise StatusException.new(response, "mkdir `#{remote}'") unless response.ok?
163-
(options[:requests] || RECURSIVE_READERS).to_i.times do
164-
break unless process_next_entry
163+
if @options[:create_dir]
164+
sftp.mkdir(remote) do |response|
165+
@active -= 1
166+
raise StatusException.new(response, "mkdir `#{remote}'") unless response.ok?
167+
(options[:requests] || RECURSIVE_READERS).to_i.times do
168+
break unless process_next_entry
169+
end
165170
end
171+
else
172+
@active -= 1
173+
process_next_entry
166174
end
167175
else
168176
raise ArgumentError, "expected a file to upload" unless local.respond_to?(:read) || ::File.exists?(local)

0 commit comments

Comments
 (0)