Class: VagrantPlugins::Scp::Command::Scp

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/scp/commands/scp.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



8
9
10
# File 'lib/vagrant/scp/commands/scp.rb', line 8

def self.synopsis
  "copies data into a box via SCP"
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant/scp/commands/scp.rb', line 12

def execute
  @file_1, @file_2 = parse_args()
  return if @file_2.nil?

  with_target_vms(host) do |machine|
    @ssh_info = machine.ssh_info
    raise Vagrant::Errors::SSHNotReady if @ssh_info.nil?
    user_at_host = "#{@ssh_info[:username]}@#{@ssh_info[:host]}"
    if net_ssh_command == :upload!
      target = "#{user_at_host}:'#{target_files}'"
      source = "'#{source_files}'"
    else
      target = "'#{target_files}'"
      source = "#{user_at_host}:'#{source_files}'"
    end
    command = [
      "scp",
      "-r",
      "-o StrictHostKeyChecking=no",
      "-o UserKnownHostsFile=/dev/null",
      "-o port=#{@ssh_info[:port]}",
      "-i '#{@ssh_info[:private_key_path][0]}'",
      source,
      target
    ].join(' ')
    system(command)
  end
end