Class: Dployr::Scripts::Scp

Inherits:
Object
  • Object
show all
Defined in:
lib/dployr/scripts/scp.rb

Instance Method Summary collapse

Constructor Details

#initialize(ip, host, username, private_key_path, script) ⇒ Scp

Returns a new instance of Scp.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dployr/scripts/scp.rb', line 7

def initialize(ip, host, username, private_key_path, script)
  begin
    puts "Connecting to #{host} (SCP)...".yellow
    Net::SCP.start(ip, username, :keys => [private_key_path]) do |scp|
      source = script["source"]
      target = script["target"]
      puts "Copying #{source} -> #{target}".yellow
      scp.upload(source, target, :recursive => true, :preserve => true)
    end
  rescue => e
    raise "Cannot copy to remote: #{e}"
  end
end