diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index 373db189a..47d7b9e84 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -317,10 +317,11 @@ module VagrantPlugins else dest = to if to.end_with?(File::SEPARATOR) - create_remote_directory(dest) dest = File.join(to, File.basename(path)) end end + @logger.debug("Ensuring remote directory exists for destination upload") + create_remote_directory(File.dirname(dest)) @logger.debug("Uploading file #{path} to remote #{dest}") upload_file = File.open(path, "rb") begin diff --git a/test/unit/plugins/communicators/ssh/communicator_test.rb b/test/unit/plugins/communicators/ssh/communicator_test.rb index 0cde8b32d..f1c8df03b 100644 --- a/test/unit/plugins/communicators/ssh/communicator_test.rb +++ b/test/unit/plugins/communicators/ssh/communicator_test.rb @@ -547,13 +547,24 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do file = Tempfile.new('vagrant-test') begin expect(scp).to receive(:upload!).with(instance_of(File), "/destination/dir/#{File.basename(file.path)}") - expect(communicator).to receive(:create_remote_directory).with("/destination/dir/") + expect(communicator).to receive(:create_remote_directory).with("/destination/dir") communicator.upload(file.path, "/destination/dir/") ensure file.delete end end + it "creates remote directory path to destination on upload" do + file = Tempfile.new('vagrant-test') + begin + expect(scp).to receive(:upload!).with(instance_of(File), "/destination/dir/file.txt") + expect(communicator).to receive(:create_remote_directory).with("/destination/dir") + communicator.upload(file.path, "/destination/dir/file.txt") + ensure + file.delete + end + end + it "raises custom error on permission errors" do file = Tempfile.new('vagrant-test') begin