Skip to content

Commit

Permalink
Merge pull request #7154 from mitchellh/pr-6316
Browse files Browse the repository at this point in the history
Create parent directories during ftp push
  • Loading branch information
sethvargo committed Mar 18, 2016
2 parents 197a2d8 + 76e7a98 commit d9b5e0e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion plugins/pushes/ftp/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class SFTPAdapter < Adapter
def initialize(*)
require "net/sftp"
super
@dirs = {}
end

def default_port
Expand All @@ -120,7 +121,23 @@ def connect(&block)
end

def upload(local, remote)
@server.upload!(local, remote, mkdir: true)
dir = File.dirname(remote)

fullpath = Pathname.new(dir)
fullpath.descend do |path|
if @dirs[path.to_s].nil?
begin
@server.mkdir!(path.to_s)

# Cache visited directories in a list to avoid duplicate requests
@dirs[path.to_s] = true
rescue Net::SFTP::StatusException => e
# Directory exists, skip...
end
end
end

@server.upload!(local, remote)
end
end
end
Expand Down

0 comments on commit d9b5e0e

Please sign in to comment.