Class: Microsandbox::SshClient
- Inherits:
-
Object
- Object
- Microsandbox::SshClient
- Defined in:
- lib/microsandbox/ssh.rb
Overview
A native, in-process SSH client session to a sandbox, from Microsandbox::SshOps#open_client. Mirrors the ‘SshClient` of the official SDKs.
Instance Method Summary collapse
-
#attach(term: nil, detach_keys: nil) ⇒ Integer
Attach the local terminal to an interactive SSH shell.
-
#close ⇒ nil
Close the SSH client session.
-
#exec(command, tty: false) ⇒ SshOutput
Run a command over SSH and collect its output.
-
#initialize(native) ⇒ SshClient
constructor
A new instance of SshClient.
-
#sftp {|sftp| ... } ⇒ SftpClient, Object
Open an SFTP session over this connection.
Constructor Details
#initialize(native) ⇒ SshClient
Returns a new instance of SshClient.
136 137 138 |
# File 'lib/microsandbox/ssh.rb', line 136 def initialize(native) @native = native end |
Instance Method Details
#attach(term: nil, detach_keys: nil) ⇒ Integer
Attach the local terminal to an interactive SSH shell. Host-TTY coupled (puts the terminal in raw mode and forwards SIGWINCH); blocks until the remote shell exits or the detach sequence is typed.
154 155 156 |
# File 'lib/microsandbox/ssh.rb', line 154 def attach(term: nil, detach_keys: nil) @native.attach(term&.to_s, detach_keys&.to_s) end |
#close ⇒ nil
Close the SSH client session. Idempotent.
175 176 177 178 |
# File 'lib/microsandbox/ssh.rb', line 175 def close @native.close nil end |
#exec(command, tty: false) ⇒ SshOutput
Run a command over SSH and collect its output.
144 145 146 |
# File 'lib/microsandbox/ssh.rb', line 144 def exec(command, tty: false) SshOutput.new(@native.exec(command.to_s, tty ? true : false)) end |
#sftp {|sftp| ... } ⇒ SftpClient, Object
Open an SFTP session over this connection. With a block, the session is yielded and closed when the block returns.
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/microsandbox/ssh.rb', line 162 def sftp session = SftpClient.new(@native.sftp) return session unless block_given? begin yield session ensure session.close end end |