Struct openssh::SessionBuilder

source ·
pub struct SessionBuilder { /* private fields */ }
Expand description

Build a Session with options.

Implementations§

source§

impl SessionBuilder

source

pub fn user(&mut self, user: String) -> &mut Self

Set the ssh user (ssh -l).

Defaults to None.

source

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

Set the port to connect on (ssh -p).

Defaults to None.

source

pub fn keyfile(&mut self, p: impl AsRef<Path>) -> &mut Self

Set the keyfile to use (ssh -i).

Defaults to None.

source

pub fn known_hosts_check(&mut self, k: KnownHosts) -> &mut Self

See KnownHosts.

Default KnownHosts::Add.

source

pub fn connect_timeout(&mut self, d: Duration) -> &mut Self

Set the connection timeout (ssh -o ConnectTimeout).

This value is specified in seconds. Any sub-second duration remainder will be ignored. Defaults to None.

source

pub fn server_alive_interval(&mut self, d: Duration) -> &mut Self

Set the timeout interval after which if no data has been received from the server, ssh will request a response from the server (ssh -o ServerAliveInterval).

This value is specified in seconds. Any sub-second duration remainder will be ignored. Defaults to None.

source

pub fn control_directory(&mut self, p: impl AsRef<Path>) -> &mut Self

Set the directory in which the temporary directory containing the control socket will be created.

If not set, ./ will be used (the current directory).

source

pub fn config_file(&mut self, p: impl AsRef<Path>) -> &mut Self

Set an alternative per-user configuration file.

By default, ssh uses ~/.ssh/config. This is equivalent to ssh -F <p>.

Defaults to None.

source

pub fn compression(&mut self, compression: bool) -> &mut Self

Enable or disable compression (including stdin, stdout, stderr, data for forwarded TCP and unix-domain connections, sftp and scp connections).

Note that the ssh server can forcibly disable the compression.

By default, ssh uses configure value set in ~/.ssh/config.

If ~/.ssh/config does not enable compression, then it is disabled by default.

source

pub fn jump_hosts<T: AsRef<str>>( &mut self, hosts: impl IntoIterator<Item = T>, ) -> &mut Self

Specify one or multiple jump hosts.

Connect to the target host by first making a ssh connection to the jump host described by destination and then establishing a TCP forwarding to the ultimate destination from there.

Multiple jump hops may be specified. This is a shortcut to specify a ProxyJump configuration directive.

Note that configuration directives specified by SessionBuilder do not apply to the jump hosts.

Use ~/.ssh/config to specify configuration for jump hosts.

source

pub fn user_known_hosts_file( &mut self, user_known_hosts_file: impl AsRef<Path>, ) -> &mut Self

Specify the path to the known_hosts file.

The path provided may use tilde notation (~) to refer to the user’s home directory.

The default is ~/.ssh/known_hosts and ~/.ssh/known_hosts2.

source

pub fn ssh_auth_sock(&mut self, ssh_auth_sock: impl AsRef<Path>) -> &mut Self

Specify the path to the ssh-agent.

The path provided may use tilde notation (~) to refer to the user’s home directory.

The default is None.

source

pub async fn connect_mux<S: AsRef<str>>( &self, destination: S, ) -> Result<Session, Error>

Connect to the host at the given host over SSH using native mux, which will create a new local socket connection for each Child created.

See the crate-level documentation for more details on the difference between native and process-based mux.

The format of destination is the same as the destination argument to ssh. It may be specified as either [user@]hostname or a URI of the form ssh://[user@]hostname[:port]. A username or port that is specified in the connection string overrides the one set in the builder (but does not change the builder).

If connecting requires interactive authentication based on STDIN (such as reading a password), the connection will fail. Consider setting up keypair-based authentication instead.

Trait Implementations§

source§

impl Clone for SessionBuilder

source§

fn clone(&self) -> SessionBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SessionBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for SessionBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more