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
# 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?
    current_file = nil
    Net::SCP.send(
      net_ssh_command,
      @ssh_info[:host],
      @ssh_info[:username],
      source_files,
      target_files,
      :recursive => true,
      :ssh => {
        :port => @ssh_info[:port],
        :keys => @ssh_info[:private_key_path],
        :verbose => 2}
    ) do |_, name, sent, total|
      message = "\r#{name}: #{(sent*100.0/total).round(3)}%"
      message = "\n{message}" unless current_file == name
      STDOUT.write message
      current_file = name
    end
  end
end