Class: Keyrack::Store::SSH

Inherits:
Object
  • Object
show all
Defined in:
lib/keyrack/store/ssh.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SSH

Returns a new instance of SSH.



4
5
6
7
8
9
# File 'lib/keyrack/store/ssh.rb', line 4

def initialize(options)
  @host = options['host']
  @user = options['user']
  @path = options['path']
  @port = options['port'] || 22
end

Instance Method Details

#readObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/keyrack/store/ssh.rb', line 11

def read
  begin
    result = nil
    Net::SSH.start(@host, @user, :port => @port) do |ssh|
      result = ssh.scp.download!(@path)
    end
    result
  rescue Net::SCP::Error
    nil
  end
end

#write(data) ⇒ Object



23
24
25
26
27
# File 'lib/keyrack/store/ssh.rb', line 23

def write(data)
  Net::SSH.start(@host, @user, :port => @port) do |ssh|
    ssh.scp.upload!(StringIO.new(data), @path)
  end
end