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



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

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

Instance Method Details

#executeObject



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
40
41
42
43
44
45
46
47
48
# File 'lib/vagrant/scp/commands/scp.rb', line 13

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

    if @ssh_info[:proxy_command]
      proxy_command = "-o ProxyCommand='#{@ssh_info[:proxy_command]}'"
    else
      proxy_command = ''
    end

    command = [
      "scp",
      "-r",
      "-o StrictHostKeyChecking=no",
      "-o UserKnownHostsFile=/dev/null",
      "-o port=#{@ssh_info[:port]}",
      proxy_command,
      "-i '#{@ssh_info[:private_key_path][0]}'",
      source,
      target
    ].join(' ')
    system(command)
  end
end