Class: Fog::SCP::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace-fog/core/scp.rb

Instance Method Summary collapse

Constructor Details

#initialize(address, username, options) ⇒ Real

Returns a new instance of Real.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rackspace-fog/core/scp.rb', line 46

def initialize(address, username, options)
  require 'net/scp'

  key_manager = Net::SSH::Authentication::KeyManager.new(nil, options)

  unless options[:key_data] || options[:keys] || options[:password] || key_manager.agent
    raise ArgumentError.new(':key_data, :keys, :password or a loaded ssh-agent is required to initialize SSH')
  end

  @address  = address
  @username = username
  @options  = { :paranoid => false }.merge(options)
end

Instance Method Details

#download(remote_path, local_path, download_options = {}) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rackspace-fog/core/scp.rb', line 72

def download(remote_path, local_path, download_options = {})
  begin
    Net::SCP.start(@address, @username, @options) do |scp|
      scp.download!(remote_path, local_path, download_options) do |ch, name, sent, total|
        # TODO: handle progress display?
      end
    end
  rescue Exception => error
    raise error
  end
end

#upload(local_path, remote_path, upload_options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rackspace-fog/core/scp.rb', line 60

def upload(local_path, remote_path, upload_options = {})
  begin
    Net::SCP.start(@address, @username, @options) do |scp|
      scp.upload!(local_path, remote_path, upload_options) do |ch, name, sent, total|
        # TODO: handle progress display?
      end
    end
  rescue Exception => error
    raise error
  end
end