// ssh2辅助模块(混合方案) // 用于SCP和rsync receiver实现 pub mod scp_handler; pub mod rsync_receiver; pub use scp_handler::ScpHandler; pub use rsync_receiver::RsyncReceiverHandler; use anyhow::Result; use ssh2::Session; use std::net::TcpStream; use std::path::Path; /// ssh2 Session管理 pub struct Ssh2Session { session: Session, } impl Ssh2Session { /// 创建新的ssh2 session(从现有TCP连接) pub fn new(tcp_stream: TcpStream) -> Result { let mut session = Session::new()?; session.set_tcp_stream(tcp_stream); session.handshake()?; Ok(Self { session }) } /// 认证(使用现有MarkBase auth系统) pub fn authenticate(&mut self, user: &str, password: &str) -> Result<()> { self.session.userauth_password(user, password)?; Ok(()) } /// 获取session引用 pub fn session(&self) -> &Session { &self.session } }