openssh_sftp_client::file

Struct File

Source
pub struct File { /* private fields */ }
Expand description

A reference to the remote file.

Cloning File instance would return a new one that shares the same underlying file handle as the existing File instance, while reads, writes and seeks can be performed independently.

If you want a file that implements tokio::io::AsyncRead and tokio::io::AsyncWrite, checkout TokioCompatFile.

Implementations§

Source§

impl File

Source

pub async fn close(self) -> Result<(), Error>

Close the File, send the close request if this is the last reference.

§Cancel Safety

This function is cancel safe.

Source

pub async fn set_metadata(&mut self, metadata: MetaData) -> Result<(), Error>

Change the metadata of a file or a directory.

§Cancel Safety

This function is cancel safe.

Source

pub async fn set_len(&mut self, size: u64) -> Result<(), Error>

Truncates or extends the underlying file, updating the size of this file to become size.

If the size is less than the current file’s size, then the file will be shrunk.

If it is greater than the current file’s size, then the file will be extended to size and have all of the intermediate data filled in with 0s.

§Cancel Safety

This function is cancel safe.

Source

pub async fn sync_all(&mut self) -> Result<(), Error>

Attempts to sync all OS-internal metadata to disk.

This function will attempt to ensure that all in-core data reaches the filesystem before returning.

§Precondition

Require extension fsync

You can check it with Sftp::support_fsync.

§Cancel Safety

This function is cancel safe.

Source

pub async fn set_permissions(&mut self, perm: Permissions) -> Result<(), Error>

Changes the permissions on the underlying file.

§Cancel Safety

This function is cancel safe.

Source

pub async fn metadata(&mut self) -> Result<MetaData, Error>

Queries metadata about the underlying file.

Source

pub async fn read( &mut self, n: u32, buffer: BytesMut, ) -> Result<Option<BytesMut>, Error>

  • n - number of bytes to read in

If the File has reached EOF or n == 0, then None is returned.

NOTE that the returned buffer might be smaller than n.

Source

pub async fn write(&mut self, buf: &[u8]) -> Result<usize, Error>

Write data into the file.

NOTE that this API might only write part of the buf.

Source

pub async fn write_vectorized( &mut self, bufs: &[IoSlice<'_>], ) -> Result<usize, Error>

Write from multiple buffer at once.

NOTE that this API might only write part of the buf.

Source

pub async fn write_zero_copy( &mut self, bytes_slice: &[Bytes], ) -> Result<usize, Error>

Zero copy write.

NOTE that this API might only write part of the buf.

Source

pub async fn read_all( &mut self, n: usize, buffer: BytesMut, ) -> Result<BytesMut, Error>

  • n - number of bytes to read in.

If n == 0 or EOF is reached, then buffer is returned unchanged.

§Cancel Safety

This function is cancel safe.

Source

pub async fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Write entire buf.

§Cancel Safety

This function is cancel safe.

Source

pub async fn write_all_vectorized( &mut self, bufs: &mut [IoSlice<'_>], ) -> Result<(), Error>

Write entire buf.

§Cancel Safety

This function is cancel safe.

Source

pub async fn write_all_zero_copy( &mut self, bufs: &mut [Bytes], ) -> Result<(), Error>

Write entire buf.

§Cancel Safety

This function is cancel safe.

Source

pub fn offset(&self) -> u64

Return the offset of the file.

Source

pub async fn copy_to( &mut self, dst: &mut Self, n: NonZeroU64, ) -> Result<(), Error>

Copy n bytes of data from self to dst.

The server MUST copy the data exactly as if the data is copied using a series of read and write.

There are no protocol restictions on this operation; however, the server MUST ensure that the user does not exceed quota, etc. The server is, as always, free to complete this operation out of order if it is too large to complete immediately, or to refuse a request that is too large.

After a successful function call, the offset of self and dst are increased by n.

§Precondition

Requires extension copy-data. For openssh-portable, this is available from V_9_0_P1.

You can check it with Sftp::support_copy.

If the extension is not supported by the server, this function would fail with Error::UnsupportedExtension.

Source

pub async fn copy_all_to(&mut self, dst: &mut Self) -> Result<(), Error>

Copy data from self to dst until EOF is encountered.

The server MUST copy the data exactly as if the data is copied using a series of read and write.

There are no protocol restictions on this operation; however, the server MUST ensure that the user does not exceed quota, etc. The server is, as always, free to complete this operation out of order if it is too large to complete immediately, or to refuse a request that is too large.

After a successful function call, the offset of self and dst are unchanged.

§Precondition

Requires extension copy-data. For openssh-portable, this is available from V_9_0_P1.

You can check it with Sftp::support_copy.

If the extension is not supported by the server, this function would fail with Error::UnsupportedExtension.

Source

pub fn as_mut_file(&mut self) -> &mut File

No-op to be compatible with TokioCompatFile::as_mut_file

Trait Implementations§

Source§

impl AsyncSeek for File

Source§

fn start_seek(self: Pin<&mut Self>, position: SeekFrom) -> Result<()>

start_seek only adjust local offset since sftp protocol does not provides a seek function.

Instead, offset is provided when sending read/write requests, thus errors are reported at read/write.

Source§

fn poll_complete( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<u64>>

This function is a no-op, it simply return the offset.

Source§

impl Clone for File

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for File

Source§

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

Formats the value using the given formatter. Read more
Source§

impl From<File> for TokioCompatFile

Source§

fn from(inner: File) -> Self

Converts to this type from the input type.
Source§

impl From<TokioCompatFile> for File

Source§

fn from(file: TokioCompatFile) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for File

§

impl !RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl !UnwindSafe for File

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<S> AsyncSeekExt for S
where S: AsyncSeek + ?Sized,

Source§

fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self>
where Self: Unpin,

Creates a future which will seek an IO object, and then yield the new position in the object and the object itself. Read more
Source§

fn rewind(&mut self) -> Seek<'_, Self>
where Self: Unpin,

Creates a future which will rewind to the beginning of the stream. Read more
Source§

fn stream_position(&mut self) -> Seek<'_, Self>
where Self: Unpin,

Creates a future which will return the current seek position from the start of the stream. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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