pub struct SshSession { /* private fields */ }Expand description
An authenticated SSH session ready for command execution.
Holds the russh client handle for the duration of its lifetime. Drop → the connection is cleaned up by russh’s internal tasks.
Wrapped in Arc to allow sharing across multiple operations (discovery + metrics).
Implementations§
Source§impl SshSession
impl SshSession
Sourcepub async fn connect(host: &Host) -> Result<Self>
pub async fn connect(host: &Host) -> Result<Self>
Connect and authenticate to host.
Authentication is attempted in order:
- SSH agent (unix only, via
SSH_AUTH_SOCK). - Identity file specified in the host config (
identity_file). - Default key files (
~/.ssh/id_ed25519,id_rsa, etc.). - Password (if provided in host config).
Returns an error when no method succeeds or the connection times out.
§Errors
- Connection timeout (> 10 s)
- Authentication failure
- Network error
Sourcepub async fn run_command(&self, cmd: &str) -> Result<String>
pub async fn run_command(&self, cmd: &str) -> Result<String>
Execute a shell command on the remote host and return its stdout.
A new SSH channel is opened for each call so sessions can be
reused across multiple commands. The remote exit status is ignored —
use SshSession::run_command_checked when it carries the result.
§Errors
Returns an error on channel failure or if the command times out (30 s).
Sourcepub async fn run_command_checked(&self, cmd: &str) -> Result<String>
pub async fn run_command_checked(&self, cmd: &str) -> Result<String>
Like SshSession::run_command but returns an error when the remote
command exits with a non-zero status. Use for test-style probes whose
exit code is the answer (e.g. sudo -n true).
§Errors
As SshSession::run_command, plus a non-zero remote exit status.
Sourcepub async fn open_sftp_channel(&self) -> Result<ChannelStream<Msg>>
pub async fn open_sftp_channel(&self) -> Result<ChannelStream<Msg>>
Opens a new SSH channel, requests the SFTP subsystem, and returns the
channel as an async stream suitable for russh_sftp::client::SftpSession::new.
The SshSession must remain alive for the entire lifetime of the
SFTP session — dropping it closes the underlying TCP connection.
§Errors
Returns an error if the channel cannot be opened or if the server rejects the SFTP subsystem request.
Sourcepub async fn disconnect(self)
pub async fn disconnect(self)
Gracefully close the SSH connection.
Trait Implementations§
Source§impl Clone for SshSession
impl Clone for SshSession
Source§fn clone(&self) -> SshSession
fn clone(&self) -> SshSession
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more