diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index da43cb23e..b009cb5ca 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -307,10 +307,11 @@ module VagrantPlugins scp_connect do |scp| uploader = lambda do |path, remote_dest=nil| if File.directory?(path) + dest = File.join(to, path.sub(/^#{Regexp.escape(from)}/, "")) + create_remote_directory(dest) Dir.new(path).each do |entry| next if entry == "." || entry == ".." full_path = File.join(path, entry) - dest = File.join(to, path.sub(/^#{Regexp.escape(from)}/, "")) create_remote_directory(dest) uploader.call(full_path, dest) end diff --git a/test/unit/plugins/communicators/ssh/communicator_test.rb b/test/unit/plugins/communicators/ssh/communicator_test.rb index d6e9d2b85..9139f0439 100644 --- a/test/unit/plugins/communicators/ssh/communicator_test.rb +++ b/test/unit/plugins/communicators/ssh/communicator_test.rb @@ -565,6 +565,16 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do end end + it "creates remote directory given an empty directory" do + file = Dir.mktmpdir + begin + expect(communicator).to receive(:create_remote_directory).with("/destination/dir/#{ File.basename(file)}/") + communicator.upload(file, "/destination/dir") + ensure + FileUtils.rm_rf(file) + end + end + it "raises custom error on permission errors" do file = Tempfile.new('vagrant-test') begin