Struct NewSession

Source
pub struct NewSession<S: AsyncRead + AsyncWrite> { /* private fields */ }
Expand description

A newly established, unauthenticated SSH session.

All you can really do with this in authenticate it using one of the authenticate_* methods. You’ll most likely want NewSession::authenticate_key.

Implementations§

Source§

impl<S: AsyncRead + AsyncWrite + 'static> NewSession<S>

Source

pub fn authenticate_key( self, user: &str, key: KeyPair, ) -> Box<dyn Future<Item = Session<S>, Error = HandlerError<()>>>
where S: Tcp,

Authenticate as the given user using the given keypair.

See also thrussh::client::Connection::authenticate_key.

Examples found in repository?
examples/ls.rs (line 25)
12fn main() {
13    // async:
14
15    let mut core = tokio_core::reactor::Core::new().unwrap();
16    let handle = core.handle();
17
18    let cmd = ::std::env::args().skip(1).next().unwrap();
19    let key = thrussh_keys::load_secret_key("/home/jon/aws-test.pem", None).unwrap();
20
21    let ls_out = TcpStream::connect(&"52.23.157.12:22".parse().unwrap(), &handle)
22        .map_err(thrussh::Error::IO)
23        .map_err(thrussh::HandlerError::Error)
24        .and_then(|c| Session::new(c, &handle))
25        .and_then(|session| session.authenticate_key("ec2-user", key))
26        .and_then(|mut session| session.open_exec(&cmd));
27
28    let channel = core.run(ls_out).unwrap();
29    let (channel, data) = core.run(tokio_io::io::read_to_end(channel, Vec::new()))
30        .unwrap();
31    println!("{}", ::std::str::from_utf8(&data[..]).unwrap());
32    let status = core.run(channel.exit_status()).unwrap();
33    println!("{}", status);
34
35    /*
36
37    // sync:
38
39    // Connect to the local SSH server
40    let tcp = TcpStream::connect("127.0.0.1:22").unwrap();
41    let mut sess = Session::new().unwrap();
42    sess.handshake(&tcp).unwrap();
43    sess.userauth_agent("username").unwrap();
44
45    let mut channel = sess.channel_session().unwrap();
46    channel.exec("ls").unwrap();
47    let mut s = String::new();
48    channel.read_to_string(&mut s).unwrap();
49    println!("{}", s);
50    channel.wait_close();
51    println!("{}", channel.exit_status().unwrap());
52    */
53}

Auto Trait Implementations§

§

impl<S> Freeze for NewSession<S>
where S: Freeze,

§

impl<S> !RefUnwindSafe for NewSession<S>

§

impl<S> !Send for NewSession<S>

§

impl<S> !Sync for NewSession<S>

§

impl<S> Unpin for NewSession<S>
where S: Unpin,

§

impl<S> !UnwindSafe for NewSession<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.