Class: Net::Simple
- Inherits:
-
Object
- Object
- Net::Simple
- Defined in:
- lib/net/simple.rb
Instance Method Summary collapse
- #close ⇒ Object
- #connect(&block) ⇒ Object
-
#download(remote, local) ⇒ Object
def sudo(command) @connection.exec!(“sudo #command”) end.
-
#initialize(host, username, password = "", verbose = :fatal) ⇒ Simple
constructor
A new instance of Simple.
- #run(command) ⇒ Object
- #upload(local, remote) ⇒ Object
- #with_connection {|_self| ... } ⇒ Object
Constructor Details
#initialize(host, username, password = "", verbose = :fatal) ⇒ Simple
Returns a new instance of Simple.
8 9 10 11 12 |
# File 'lib/net/simple.rb', line 8 def initialize(host, username, password="", verbose = :fatal) @host = host @username = username @ssh_options = {:password => password, :verbose => verbose} end |
Instance Method Details
#close ⇒ Object
29 30 31 |
# File 'lib/net/simple.rb', line 29 def close @connection.close end |
#connect(&block) ⇒ Object
14 15 16 17 |
# File 'lib/net/simple.rb', line 14 def connect(&block) @connection ||= Net::SSH.start(@host, @username, @ssh_options) block_given? ? (instance_eval(&block) and close) : @connection end |
#download(remote, local) ⇒ Object
def sudo(command)
@connection.exec!("sudo #{command}")
end
37 38 39 |
# File 'lib/net/simple.rb', line 37 def download(remote, local) Net::SCP.download!(@host, @username, remote, local, :ssh => @ssh_options) end |
#run(command) ⇒ Object
25 26 27 |
# File 'lib/net/simple.rb', line 25 def run(command) @connection.exec!(command) end |
#upload(local, remote) ⇒ Object
41 42 43 |
# File 'lib/net/simple.rb', line 41 def upload(local, remote) Net::SCP.upload!(@host, @username, local, remote, :ssh => @ssh_options) end |
#with_connection {|_self| ... } ⇒ Object
19 20 21 22 23 |
# File 'lib/net/simple.rb', line 19 def with_connection(&block) connect yield self if block_given? close end |