Skip to content

Instantly share code, notes, and snippets.

@opensourcegeek
Created February 21, 2018 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save opensourcegeek/396fe8d50111f528f7dfc0bac608f790 to your computer and use it in GitHub Desktop.
Save opensourcegeek/396fe8d50111f528f7dfc0bac608f790 to your computer and use it in GitHub Desktop.
Failing code
extern crate ssh2;
use std::net::TcpStream;
use ssh2::Session;
fn create_session() -> Session {
let tcp = TcpStream::connect("test:22").expect("Cannot connect");
let mut sess = Session::new().expect("cannot start session");
sess.handshake(&tcp).expect("handshake failed");
sess.userauth_password("test", "boo").expect("Cannot authenticate");
assert!(sess.authenticated());
sess
}
struct Sample<'a> {
// session: Session,
sftp: ssh2::Sftp<'a>
}
impl <'a> Sample<'a> {
fn new(sftp: ssh2::Sftp<'a>) -> Sample<'a> {
Sample {
// session: s,
sftp
}
}
fn print_some(&self) -> () {
println!("Got it!!");
}
}
fn main() {
let sess = create_session();
let sftp = sess.sftp();
match sftp {
Ok(sftp) => {
let s = Sample::new(sftp);
s.print_some();
},
Err(e) => {
println!("Cannot start sftp {:?}", e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment