use std::net::TcpStream;
use std::io::Read;
use ssh2::Session;
use std::path::Path;
fn main() {
let tcp = TcpStream::connect("127.0.0.1:22").unwrap();
let mut sess = Session::new().unwrap();
sess.set_tcp_stream(tcp);
sess.handshake().unwrap();
sess.userauth_password("user", "password").unwrap();
let mut contents:Vec<u8> = Vec::new();
let sftp = sess.sftp().unwrap();
let mut stream = sftp.open(Path::new("/tmp/test.txt")).unwrap();
stream.read_to_end(&mut contents).unwrap();
let _ = std::fs::write(r"/tmp/test_out.txt", &contents);
}
Rust — SSH2 sftp download file
Добавить комментарий