#[cfg(feature = "libssh")]
#[cfg_attr(docsrs, doc(cfg(feature = "libssh")))]
mod libssh;
#[cfg(feature = "libssh2")]
#[cfg_attr(docsrs, doc(cfg(feature = "libssh2")))]
mod libssh2;
#[cfg(feature = "russh")]
#[cfg_attr(docsrs, doc(cfg(feature = "russh")))]
mod russh;
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use remotefs::fs::{Metadata, ReadStream, WriteStream};
use remotefs::{File, RemoteResult};
#[cfg(feature = "libssh")]
#[cfg_attr(docsrs, doc(cfg(feature = "libssh")))]
pub use self::libssh::LibSshSession;
#[cfg(feature = "libssh2")]
#[cfg_attr(docsrs, doc(cfg(feature = "libssh2")))]
pub use self::libssh2::LibSsh2Session;
#[cfg(feature = "russh")]
#[cfg_attr(docsrs, doc(cfg(feature = "russh")))]
pub use self::russh::{NoCheckServerKey, RusshSession};
use crate::SshOpts;
pub trait SshSession: Sized {
type Sftp: Sftp;
fn connect(opts: &SshOpts) -> RemoteResult<Self>;
fn disconnect(&self) -> RemoteResult<()>;
fn banner(&self) -> RemoteResult<Option<String>>;
fn authenticated(&self) -> RemoteResult<bool>;
fn cmd<S>(&mut self, cmd: S) -> RemoteResult<(u32, String)>
where
S: AsRef<str>;
fn cmd_at<S>(&mut self, cmd: S, path: &Path) -> RemoteResult<(u32, String)>
where
S: AsRef<str>,
{
self.cmd(format!("cd \"{}\"; {}", path.display(), cmd.as_ref()))
}
fn scp_recv(&self, path: &Path) -> RemoteResult<Box<dyn Read + Send>>;
fn scp_send(
&self,
remote_path: &Path,
mode: i32,
size: u64,
times: Option<(u64, u64)>,
) -> RemoteResult<Box<dyn Write + Send>>;
fn sftp(&self) -> RemoteResult<Self::Sftp>;
}
pub trait Sftp {
fn mkdir(&self, path: &Path, mode: i32) -> RemoteResult<()>;
fn open_read(&self, path: &Path) -> RemoteResult<ReadStream>;
fn open_write(&self, path: &Path, flags: WriteMode, mode: i32) -> RemoteResult<WriteStream>;
fn readdir<T>(&self, dirname: T) -> RemoteResult<Vec<File>>
where
T: AsRef<Path>;
fn realpath(&self, path: &Path) -> RemoteResult<PathBuf>;
fn rename(&self, src: &Path, dest: &Path) -> RemoteResult<()>;
fn rmdir(&self, path: &Path) -> RemoteResult<()>;
fn setstat(&self, path: &Path, metadata: Metadata) -> RemoteResult<()>;
fn stat(&self, filename: &Path) -> RemoteResult<File>;
fn symlink(&self, path: &Path, target: &Path) -> RemoteResult<()>;
fn unlink(&self, path: &Path) -> RemoteResult<()>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WriteMode {
Append,
Truncate,
}