Struct openssh_sftp_client::Sftp
source · pub struct Sftp { /* private fields */ }
Expand description
A file-oriented channel to a remote host.
Implementations§
source§impl Sftp
impl Sftp
sourcepub async fn from_session(
session: Session,
options: SftpOptions
) -> Result<Self, Error>
Available on crate feature openssh
only.
pub async fn from_session( session: Session, options: SftpOptions ) -> Result<Self, Error>
openssh
only.Create Sftp
from openssh::Session
.
Calling Sftp::close
on sftp instances created using this function
would also await on openssh::RemoteChild::wait
and
openssh::Session::close
and propagate their error in
Sftp::close
.
sourcepub async fn from_session_with_check_connection(
session: Session,
options: SftpOptions,
check_openssh_connection: impl CheckOpensshConnection + Send + Sync + 'static
) -> Result<Self, Error>
Available on crate feature openssh
only.
pub async fn from_session_with_check_connection( session: Session, options: SftpOptions, check_openssh_connection: impl CheckOpensshConnection + Send + Sync + 'static ) -> Result<Self, Error>
openssh
only.Similar to Sftp::from_session
, but takes an additional parameter
for checking if the connection is still alive.
§Example
fn check_connection<'session>(
session: &'session openssh::Session,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<(), openssh::Error>> + Send + Sync + 'session>> {
Box::pin(async move {
loop {
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
session.check().await?;
}
Ok(())
})
}
openssh_sftp_client::Sftp::from_session_with_check_connection(
openssh::Session::connect_mux("me@ssh.example.com", openssh::KnownHosts::Strict).await?,
openssh_sftp_client::SftpOptions::default(),
check_connection,
).await?;
source§impl Sftp
impl Sftp
sourcepub async fn new<W: AsyncWrite + Send + 'static, R: AsyncRead + Send + 'static>(
stdin: W,
stdout: R,
options: SftpOptions
) -> Result<Self, Error>
pub async fn new<W: AsyncWrite + Send + 'static, R: AsyncRead + Send + 'static>( stdin: W, stdout: R, options: SftpOptions ) -> Result<Self, Error>
Create Sftp
.
sourcepub async fn new_with_auxiliary<W: AsyncWrite + Send + 'static, R: AsyncRead + Send + 'static>(
stdin: W,
stdout: R,
options: SftpOptions,
auxiliary: SftpAuxiliaryData
) -> Result<Self, Error>
pub async fn new_with_auxiliary<W: AsyncWrite + Send + 'static, R: AsyncRead + Send + 'static>( stdin: W, stdout: R, options: SftpOptions, auxiliary: SftpAuxiliaryData ) -> Result<Self, Error>
Create Sftp
with some auxiliary data.
The auxiliary data will be dropped after all sftp requests has been
sent(flush_task), all responses processed (read_task) and Sftp
has
been dropped.
If you want to get back the data, you can simply use
SftpAuxiliaryData::Arced
and then stores an Arc
elsewhere.
Once the sftp tasks is completed and Sftp
is dropped, you can call
Arc::try_unwrap
to get back the exclusive ownership of it.
sourcepub async fn close(self) -> Result<(), Error>
pub async fn close(self) -> Result<(), Error>
Close sftp connection
If sftp is created using Sftp::from_session
, then calling this
function would also await on openssh::RemoteChild::wait
and
openssh::Session::close
and propagate their error in
Sftp::close
.
sourcepub fn options(&self) -> OpenOptions
pub fn options(&self) -> OpenOptions
Return a new OpenOptions
object.
sourcepub async fn create(&self, path: impl AsRef<Path>) -> Result<File, Error>
pub async fn create(&self, path: impl AsRef<Path>) -> Result<File, Error>
Opens a file in write-only mode.
This function will create a file if it does not exist, and will truncate it if it does.
sourcepub async fn open(&self, path: impl AsRef<Path>) -> Result<File, Error>
pub async fn open(&self, path: impl AsRef<Path>) -> Result<File, Error>
Attempts to open a file in read-only mode.
sourcepub fn fs(&self) -> Fs
pub fn fs(&self) -> Fs
Fs
defaults to the current working dir set by remote sftp-server
,
which usually is the home directory.
sourcepub fn support_expand_path(&self) -> bool
pub fn support_expand_path(&self) -> bool
Check if the remote server supports the expand path extension.
If it returns true, then Fs::canonicalize
with expand path is supported.
sourcepub fn support_fsync(&self) -> bool
pub fn support_fsync(&self) -> bool
Check if the remote server supports the fsync extension.
If it returns true, then File::sync_all
is supported.
sourcepub fn support_hardlink(&self) -> bool
pub fn support_hardlink(&self) -> bool
Check if the remote server supports the hardlink extension.
If it returns true, then Fs::hard_link
is supported.
sourcepub fn support_posix_rename(&self) -> bool
pub fn support_posix_rename(&self) -> bool
Check if the remote server supports the posix rename extension.
If it returns true, then Fs::rename
will use posix rename.
sourcepub fn support_copy(&self) -> bool
pub fn support_copy(&self) -> bool
Check if the remote server supports the copy data extension.
If it returns true, then File::copy_to
and File::copy_all_to
are supported.