From f11ec8ff1a5ade7b9483822a27709bfb82ab7113 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 18:06:51 -0500 Subject: [PATCH] Make parent directories when uploading to FTP --- plugins/pushes/ftp/adapter.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 #