Skip to content

Commit ccf4298

Browse files
Pablo MerinoPablo Merino
authored andcommitted
Added option to create directory on directory upload
1 parent a9a8064 commit ccf4298

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

InstalledFiles

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp.rb
2+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/constants.rb
3+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/errors.rb
4+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/packet.rb
5+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol.rb
6+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/request.rb
7+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/response.rb
8+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/session.rb
9+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/version.rb
10+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/operations/dir.rb
11+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/operations/download.rb
12+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/operations/file.rb
13+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/operations/file_factory.rb
14+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/operations/upload.rb
15+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/base.rb
16+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/01/attributes.rb
17+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/01/base.rb
18+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/01/name.rb
19+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/02/base.rb
20+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/03/base.rb
21+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/04/attributes.rb
22+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/04/base.rb
23+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/04/name.rb
24+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/05/base.rb
25+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/06/attributes.rb
26+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/protocol/06/base.rb
27+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/operations/upload.rb
28+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/operations/upload.rb
29+
/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/net/sftp/operations/upload.rb

config.save

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
prefix=/Users/pablo/.rvm/rubies/ruby-1.9.3-p125
2+
std-ruby=$prefix/lib/ruby/1.9.1
3+
site-ruby-common=$prefix/lib/ruby/site_ruby
4+
site-ruby=$prefix/lib/ruby/site_ruby/1.9.1
5+
bin-dir=$prefix/bin
6+
rb-dir=$site-ruby
7+
so-dir=$prefix/lib/ruby/site_ruby/1.9.1/x86_64-darwin11.3.0
8+
data-dir=$prefix/share
9+
ruby-path=/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
10+
ruby-prog=/Users/pablo/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
11+
make-prog=make
12+
without-ext=no

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)