pub struct Session { /* private fields */ }Expand description
An SSH session handle that provides methods for executing commands, transferring files, and managing interactive shells.
Use Session::init to create a new session builder.
Implementations§
Source§impl<'sb> Session
impl<'sb> Session
Sourcepub fn init() -> SessionBuilder<'sb>
pub fn init() -> SessionBuilder<'sb>
Creates a new session builder with default settings.
Defaults:
- Host:
localhost - User:
root - Port:
22 - Command:
bash - Inactivity timeout: 3000 seconds
§Example
use simple_ssh::Session;
let session = Session::init()
.with_host("example.com")
.with_user("admin")
.with_passwd("secret")
.build();Sourcepub async fn connect(self) -> Result<Self>
pub async fn connect(self) -> Result<Self>
Connects to the SSH server using the configured authentication method.
§Errors
Returns an error if:
- The hostname cannot be resolved
- The connection fails
- Authentication fails
Sourcepub fn pty_builder(&mut self) -> PtyBuilder<'_>
pub fn pty_builder(&mut self) -> PtyBuilder<'_>
Sourcepub async fn run(&mut self) -> Result<u32>
pub async fn run(&mut self) -> Result<u32>
Runs the configured command with output to stdout and stderr.
Uses the command specified via SessionBuilder::with_cmd.
§Returns
The exit code of the command.
§Errors
Returns an error if no connection is established.
Auto Trait Implementations§
impl Freeze for Session
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more