Giter Site home page Giter Site logo

blmaier / async-ssh2-tokio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miyoshi-ryota/async-ssh2-tokio

0.0 0.0 0.0 102 KB

asynchronous and easy-to-use high level ssh client library for rust

License: Apache License 2.0

Shell 11.96% Rust 83.87% Dockerfile 4.17%

async-ssh2-tokio's Introduction

async-ssh2-tokio

Unit Test Status Lint Status Docs.rs Crates.io

This library is an asynchronous and easy-to-use high level ssh client library for rust with the tokio runtime. Powered by the rust ssh implementation russh.

Features

  • Connect to a SSH Host
  • Execute commands on the remote host
  • Get the stdout and exit code of the command

Install

[dependencies]
tokio = "1"
async-ssh2-tokio = "0.8.7"

Usage

use async_ssh2_tokio::client::{Client, AuthMethod, ServerCheckMethod};
#[tokio::main]
async fn main() -> Result<(), async_ssh2_tokio::Error> {
    // if you want to use key auth, then use following:
    // AuthMethod::with_key_file("key_file_name", Some("passphrase"));
    // or
    // AuthMethod::with_key_file("key_file_name", None);
    // or
    // AuthMethod::with_key(key: &str, passphrase: Option<&str>)
    let auth_method = AuthMethod::with_password("root");
    let mut client = Client::connect(
        ("10.10.10.2", 22),
        "root",
        auth_method,
        ServerCheckMethod::NoCheck,
    ).await?;

    let result = client.execute("echo Hello SSH").await?;
    assert_eq!(result.stdout, "Hello SSH\n");
    assert_eq!(result.exit_status, 0);

    let result = client.execute("echo Hello Again :)").await?;
    assert_eq!(result.stdout, "Hello Again :)\n");
    assert_eq!(result.exit_status, 0);

    Ok(())
}

Running Tests

  1. install docker and docker-compose
  2. run shellscript ./tests/run_unit_tests.sh

async-ssh2-tokio's People

Contributors

miyoshi-ryota avatar cybersoulk avatar mwileczka avatar mtsbucy1 avatar cheban1996 avatar rukai avatar czadamv avatar avgrocks avatar qpalzmqaz123 avatar packetsource avatar banyc avatar matthiasbeyer avatar chanderlud 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.