Skip to main content

SessionBuilder

Struct SessionBuilder 

Source
pub struct SessionBuilder<'sb> { /* private fields */ }
Expand description

Builder for configuring and creating an SSH Session.

Use Session::init to create a new builder, then chain configuration methods, and finally call SessionBuilder::build to create the session.

§Example

use simple_ssh::Session;

let session = Session::init()
    .with_host("example.com")
    .with_user("admin")
    .with_port(2222)
    .with_passwd("secret")
    .build()
    .expect("Failed to build session");

Implementations§

Source§

impl<'sb> SessionBuilder<'sb>

Source

pub fn with_cert_opt(self, cert: Option<PathBuf>) -> Self

Sets the SSH certificate path option.

§Arguments
  • cert - Optional path to the certificate file
Source

pub fn with_key_opt(self, key: Option<PathBuf>) -> Self

Sets the SSH private key path option.

§Arguments
  • key - Optional path to the private key file
Source

pub fn with_cert(self, cert: PathBuf) -> Self

Sets the SSH certificate path for authentication.

§Arguments
  • cert - Path to the certificate file
Source

pub fn with_key(self, key: PathBuf) -> Self

Sets the SSH private key path for authentication.

When a key is provided, public key authentication is used.

§Arguments
  • key - Path to the private key file
Source

pub fn with_port(self, port: u16) -> Self

Sets the SSH port.

§Arguments
  • port - Port number (default: 22)
Source

pub fn with_host(self, host: &'sb str) -> Self

Sets the target host.

§Arguments
  • host - Hostname or IP address
Source

pub fn with_user(self, user: &'sb str) -> Self

Sets the username for authentication.

§Arguments
  • user - Username (default: “root”)
Source

pub fn with_cmd(self, cmdv: Vec<String>) -> Self

Sets the command to execute for interactive sessions.

§Arguments
  • cmdv - Command and its arguments as a vector
Source

pub fn with_passwd(self, passwd: &str) -> Self

Sets the password for authentication.

When a password is provided (and no key), password authentication is used.

§Arguments
  • passwd - Password string
Source

pub fn with_passwd_opt(self, passwd: Option<String>) -> Self

Sets the password option for authentication.

§Arguments
  • passwd - Optional password string
Source

pub fn with_scope(self, scope: &str) -> Self

Sets the IPv6 scope ID (interface name or number).

Required for link-local IPv6 addresses.

§Arguments
  • scope - Interface name (e.g., “eth0”) or numeric scope ID
Source

pub fn with_inactivity_timeout(self, timeout: Option<Duration>) -> Self

Sets the inactivity timeout for the SSH connection.

Set to None to disable the timeout.

§Arguments
  • timeout - Optional duration for inactivity timeout
Source

pub fn build(self) -> Result<Session>

Builds the Session with the configured settings.

§Returns

A Result containing the configured Session or an error.

§Authentication Priority
  1. If a key is provided, use public key authentication
  2. If a password is provided, use password authentication
  3. Otherwise, use no authentication (none)

Auto Trait Implementations§

§

impl<'sb> Freeze for SessionBuilder<'sb>

§

impl<'sb> RefUnwindSafe for SessionBuilder<'sb>

§

impl<'sb> Send for SessionBuilder<'sb>

§

impl<'sb> Sync for SessionBuilder<'sb>

§

impl<'sb> Unpin for SessionBuilder<'sb>

§

impl<'sb> UnwindSafe for SessionBuilder<'sb>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V