use std::net::TcpStream;
use std::io::Write;
use std::io::Read;
use std::fs::File;
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", "pass").unwrap();
let sftp = sess.sftp().unwrap();
let mut local_file = File::open("/tmp/test.txt").expect("no file found");
let mut buffer:Vec<u8> = Vec::new();
let _ :u64 = local_file.read_to_end(&mut buffer).unwrap().try_into().unwrap();
sftp.create(&Path::new("/tmp/file.json"))
.unwrap()
.write_all(&buffer)
.unwrap();
}
Rust — sftp upload file
Добавить комментарий