Crate thrussh_client [] [src]

This is an SSH client library, designed to read configuration files in the same format as OpenSSH.

extern crate thrussh_client;
extern crate env_logger;
use thrussh_client::*;
use std::io::Write;

fn main() {
    env_logger::init().unwrap();
    let mut client = thrussh_client::Client::new();
    client.set_host("localhost");
    client.default_ssh_config().unwrap();
    let mut client = client.connect().unwrap();
    if let Some(key) = client.authenticate().unwrap() {
        client.learn_host(&key).unwrap();
        assert!(client.authenticate().unwrap().is_none());
    }

    struct C;
    impl thrussh_client::Handler for C {
        fn data(&mut self,
                _: u32,
                _: Option<u32>,
                data: &[u8],
                _: &mut Session)
                -> Result<(), Error> {
            try!(std::io::stdout().write(data));
            Ok(())
        }
    }
    let mut c = C;
    let channel0 = client.channel_open_session().unwrap();
    client.wait_channel_open(&mut c, channel0).unwrap();
    client.exec(channel0, false, "ls -l");
    client.eof(channel0);

    let channel1 = client.channel_open_session().unwrap();
    client.wait_channel_open(&mut c, channel1).unwrap();
    client.data(channel1, None, b"blabla blibli").unwrap();
    client.eof(channel1);
    client.close(channel1);

    client.wait_channel_close(&mut c, channel0).unwrap();
}

Structs

Client
Session

Enums

ClientError
Error

Traits

Handler

Functions

check_known_hosts

Check whether the host is known, from its standard location.

learn_known_hosts

Record a host's public key into the user's known_hosts file.

Type Definitions

Connected