use russh::client::Handler;
#[doc(no_inline)]
pub use russh_sftp::client::error::Error as SftpError;
use russh_sftp::client::SftpSession;
use crate::{AsyncChannel, AsyncSession, SshError};
impl<H: 'static + Handler> AsyncSession<H> {
#[cfg(feature = "sftp")]
pub async fn open_sftp(&self) -> Result<SftpSession, SshOrSftpError> {
let channel = self.open_channel().await?;
channel.request_subsystem(true, "sftp").await?;
let sftp = channel.sftp().await?;
Ok(sftp)
}
}
impl AsyncChannel {
#[cfg(feature = "sftp")]
pub async fn sftp(&self) -> Result<SftpSession, SftpError> {
SftpSession::new(tokio::io::join(self.stdout(), self.stdin())).await
}
}
#[derive(Debug, thiserror::Error)]
pub enum SshOrSftpError {
#[error("SSH Error: {0}")]
Ssh(#[from] SshError),
#[error("SFTP Error: {0}")]
Sftp(#[from] SftpError),
}