diff --git a/plugins/pushes/ftp/adapter.rb b/plugins/pushes/ftp/adapter.rb index 9b08a0146..8a9414376 100644 --- a/plugins/pushes/ftp/adapter.rb +++ b/plugins/pushes/ftp/adapter.rb @@ -1,3 +1,5 @@ +require "pathname" + module VagrantPlugins module FTPPush class Adapter @@ -67,16 +69,25 @@ module VagrantPlugins end def upload(local, remote) - parent = File.dirname(remote) + parent = File.dirname(remote) + fullpath = Pathname.new(File.expand_path(parent, pwd)) - # Create the parent directory if it does not exist - if !@server.list("/").any? { |f| f.start_with?(parent) } - @server.mkdir(parent) + # Create the parent directories if they does not exist (naive mkdir -p) + fullpath.descend do |path| + if @server.list(path.to_s).empty? + @server.mkdir(path.to_s) + end end # Upload the file @server.putbinaryfile(local, remote) end + + private + + def pwd + @pwd ||= @server.pwd + end end #