Skip to content

pbar1/ssh2-async-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ssh2-async

Runtime-agnostic async wrappers for ssh2.

Includes pluggable runtime support through the RuntimeContext trait to intelligently support async without resorting to busy-waiting. Tokio support is implemented already and enabled by default.

Also implements futures::io::{AsyncRead, AsyncWrite} for things that implement std::io::{Read, Write} in ssh2, such as channels and files.

Example

use futures::AsyncReadExt;
use ssh2_async::{Session, TokioContext};
use tokio::net::TcpStream;

#[tokio::main]
async fn main() -> Result<(), ssh2::Error> {
    let tcp = TcpStream::connect("127.0.0.1:22")
        .await
        .unwrap()
        .into_std()
        .unwrap();

    let mut session = Session::<TokioContext>::from_stream(tcp)?;
    session.handshake().await?;
    session.userauth_password("user", "password").await?;

    let mut channel = session.channel_session().await?;
    channel.exec("uname -a").await?;

    let mut output = String::new();
    channel.read_to_string(&mut output).await.unwrap();
    channel.wait_close().await?;

    println!("{output}");
    Ok(())
}

About

Performant and runtime-agnostic async wrapper for ssh2-rs

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages