Giter Site home page Giter Site logo

tokio-ssh2's Introduction

tokio-ssh2

Asynchronous ssh2 client for tokio.

This crate is build on top of tokio and ssh2. All api are same as ssh2 but support async.

Example

use tokio_ssh2::AsyncSession;
use anyhow::Result;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

#[tokio::main]
async fn main() -> Result<()> {
    let tcp = std::net::TcpStream::connect("127.0.0.1:22")?;
    let mut session = AsyncSession::new(tcp)?;
    
    session.handshake().await?;
    session.userauth_password("root", "root").await?;
    
    let mut channel = session.channel_session().await?;
    channel.request_pty("xterm-256color", None, None).await?;
    channel.shell().await?;
    
    let stream = channel.stream(0)?;
    let mut line = String::new();
    
    stream.write_all("ls".as_bytes()).await?;
    stream.read_to_string(&mut line).await?;
    
    println!("{}", line);
    
    Ok(())
}

Limitation

  • Only support std TcpStream, not tokio::net::TcpStream or serial. Will be supported once AsyncHandle stable in tokio. See issue 3781.
  • Only unix, Windows will be support soon.

tokio-ssh2's People

Contributors

tyan-boot avatar

Stargazers

lack avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.