Skip to content

Instantly share code, notes, and snippets.

@mbrubeck
Forked from opensourcegeek/ssh2-sample.rs
Created February 21, 2018 22:27
Show Gist options
  • Save mbrubeck/60e794d5f6437a49c25fcd2fa276aee0 to your computer and use it in GitHub Desktop.
Save mbrubeck/60e794d5f6437a49c25fcd2fa276aee0 to your computer and use it in GitHub Desktop.
Failing code
extern crate ssh2;
use std::net::TcpStream;
use ssh2::Session;
fn create_session() -> (TcpStream, 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());
(tcp, 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 (_stream, 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