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.
141 142 143 |
# File 'lib/microsandbox/ssh.rb', line 141 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.
159 160 161 |
# File 'lib/microsandbox/ssh.rb', line 159 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.
180 181 182 183 |
# File 'lib/microsandbox/ssh.rb', line 180 def close @native.close nil end |
#exec(command, tty: false) ⇒ SshOutput
Run a command over SSH and collect its output.
149 150 151 |
# File 'lib/microsandbox/ssh.rb', line 149 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.
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/microsandbox/ssh.rb', line 167 def sftp session = SftpClient.new(@native.sftp) return session unless block_given? begin yield session ensure session.close end end |