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

source

pub async fn from_session( session: Session, options: SftpOptions ) -> Result<Self, Error>

Available on crate feature 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.

source

pub 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.

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

source

pub async fn new<W: AsyncWrite + Send + 'static, R: AsyncRead + Send + 'static>( stdin: W, stdout: R, options: SftpOptions ) -> Result<Self, Error>

Create Sftp.

source

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.

source

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.

source

pub fn options(&self) -> OpenOptions

Return a new OpenOptions object.

source

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.

source

pub async fn open(&self, path: impl AsRef<Path>) -> Result<File, Error>

Attempts to open a file in read-only mode.

source

pub fn fs(&self) -> Fs

Fs defaults to the current working dir set by remote sftp-server, which usually is the home directory.

source

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.

source

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.

Check if the remote server supports the hardlink extension.

If it returns true, then Fs::hard_link is supported.

source

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.

source

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.

Trait Implementations§

source§

impl Debug for Sftp

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Sftp

§

impl !RefUnwindSafe for Sftp

§

impl Send for Sftp

§

impl Sync for Sftp

§

impl Unpin for Sftp

§

impl !UnwindSafe for Sftp

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more