Struct suppaftp::ImplAsyncFtpStream

source ·
pub struct ImplAsyncFtpStream<T>
where T: AsyncTlsStream,
{ /* private fields */ }
Available on crate feature async only.
Expand description

Stream to interface with the FTP server. This interface is only for the command stream.

Implementations§

source§

impl<T> ImplAsyncFtpStream<T>
where T: AsyncTlsStream,

source

pub async fn connect<A: ToSocketAddrs>(addr: A) -> FtpResult<Self>

source

pub async fn connect_timeout( addr: SocketAddr, timeout: Duration ) -> FtpResult<Self>

Try to connect to the remote server but with the specified timeout

source

pub async fn connect_with_stream(stream: TcpStream) -> FtpResult<Self>

Connect using provided configured tcp stream

source

pub async fn into_secure( self, tls_connector: impl AsyncTlsConnector<Stream = T> + Send + Sync + 'static, domain: &str ) -> FtpResult<Self>

Available on crate feature async-secure only.

Switch to secure mode if possible (FTPS), using a provided SSL configuration. This method does nothing if the connect is already secured.

§Example
use suppaftp::ImplAsyncFtpStream;
use suppaftp::async_native_tls::{TlsConnector, TlsStream};
use std::path::Path;

// Create a TlsConnector
// NOTE: For custom options see <https://docs.rs/native-tls/0.2.6/native_tls/struct.TlsConnectorBuilder.html>
let mut ctx = TlsConnector::new();
let mut ftp_stream = ImplAsyncFtpStream::connect("127.0.0.1:21").await.unwrap();
let mut ftp_stream = ftp_stream.into_secure(ctx, "localhost").await.unwrap();
Run
source

pub async fn connect_secure_implicit<A: ToSocketAddrs>( addr: A, tls_connector: impl AsyncTlsConnector<Stream = T> + Send + Sync + 'static, domain: &str ) -> FtpResult<Self>

Available on crate features async-secure and deprecated only.

Connect to remote ftps server using IMPLICIT secure connection.

Warning: mind that implicit ftps should be considered deprecated, if you can use explicit mode with into_secure()

§Example
use suppaftp::ImplAsyncFtpStream;
use suppaftp::native_tls::{TlsConnector, TlsStream};
use std::path::Path;

// Create a TlsConnector
// NOTE: For custom options see <https://docs.rs/native-tls/0.2.6/native_tls/struct.TlsConnectorBuilder.html>
let mut ctx = TlsConnector::new();
let mut ftp_stream = ImplAsyncFtpStream::connect_secure_implicit("127.0.0.1:990", ctx, "localhost").await.unwrap();
Run
source

pub fn active_mode(self, listener_timeout: Duration) -> Self

Enable active mode for data channel

source

pub fn get_welcome_msg(&self) -> Option<&str>

Returns welcome message retrieved from server (if available)

source

pub fn set_mode(&mut self, mode: Mode)

Set mode

source

pub fn set_passive_nat_workaround(&mut self, nat_workaround: bool)

Set NAT workaround for passive mode

source

pub async fn get_ref(&self) -> &TcpStream

Returns a reference to the underlying TcpStream.

source

pub async fn login<S: AsRef<str>>( &mut self, user: S, password: S ) -> FtpResult<()>

Log in to the FTP server.

source

pub async fn clear_command_channel(self) -> FtpResult<Self>

Available on crate feature async-secure only.

Perform clear command channel (CCC). Once the command is performed, the command channel will be encrypted no more. The data stream will still be secure.

source

pub async fn cwd<S: AsRef<str>>(&mut self, path: S) -> FtpResult<()>

Change the current directory to the path specified.

source

pub async fn cdup(&mut self) -> FtpResult<()>

Move the current directory to the parent directory.

source

pub async fn pwd(&mut self) -> FtpResult<String>

Gets the current directory

source

pub async fn noop(&mut self) -> FtpResult<()>

This does nothing. This is usually just used to keep the connection open.

source

pub async fn eprt(&mut self, address: SocketAddr) -> FtpResult<()>

The EPRT command allows for the specification of an extended address for the data connection. The extended address MUST consist of the network protocol as well as the network and transport addresses

source

pub async fn mkdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>

This creates a new directory on the server.

source

pub async fn transfer_type(&mut self, file_type: FileType) -> FtpResult<()>

Sets the type of file to be transferred. That is the implementation of TYPE command.

source

pub async fn quit(&mut self) -> FtpResult<()>

Quits the current FTP session.

source

pub async fn rename<S: AsRef<str>>( &mut self, from_name: S, to_name: S ) -> FtpResult<()>

Renames the file from_name to to_name

source

pub async fn retr<S, F, U>(&mut self, file_name: S, reader: F) -> FtpResult<U>
where F: FnMut(&mut dyn Read) -> FtpResult<U>, S: AsRef<str>,

The implementation of RETR command where filename is the name of the file to download from FTP and reader is the function which operates with the data stream opened.

source

pub async fn retr_as_stream<S: AsRef<str>>( &mut self, file_name: S ) -> FtpResult<DataStream<T>>

Retrieves the file name specified from the server as a readable stream. This method is a more complicated way to retrieve a file. The reader returned should be dropped. Also you will have to read the response to make sure it has the correct value. Once file has been read, call finalize_retr_stream()

source

pub async fn finalize_retr_stream(&mut self, stream: impl Read) -> FtpResult<()>

Finalize retr stream; must be called once the requested file, got previously with retr_as_stream() has been read

source

pub async fn rmdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>

Removes the remote pathname from the server.

source

pub async fn rm<S: AsRef<str>>(&mut self, filename: S) -> FtpResult<()>

Remove the remote file from the server.

source

pub async fn put_file<S, R>(&mut self, filename: S, r: &mut R) -> FtpResult<u64>
where R: Read + Unpin, S: AsRef<str>,

This stores a file on the server. r argument must be any struct which implemenents the Read trait

source

pub async fn put_with_stream<S: AsRef<str>>( &mut self, filename: S ) -> FtpResult<DataStream<T>>

Send PUT command and returns a BufWriter, which references the file created on the server The returned stream must be then correctly manipulated to write the content of the source file to the remote destination The stream must be then correctly dropped. Once you’ve finished the write, YOU MUST CALL THIS METHOD: finalize_put_stream

source

pub async fn finalize_put_stream( &mut self, stream: impl Write + Unpin ) -> FtpResult<()>

Finalize put when using stream This method must be called once the file has been written and put_with_stream has been used to write the file

source

pub async fn append_with_stream<S: AsRef<str>>( &mut self, filename: S ) -> FtpResult<DataStream<T>>

Open specified file for appending data. Returns the stream to append data to specified file. Once you’ve finished the write, YOU MUST CALL THIS METHOD: finalize_put_stream

source

pub async fn append_file<R>( &mut self, filename: &str, r: &mut R ) -> FtpResult<u64>
where R: Read + Unpin,

Append data from reader to file at filename

source

pub async fn abort<R>(&mut self, data_stream: R) -> FtpResult<()>
where R: Read + Unpin + 'static,

abort the previous FTP service command

source

pub async fn resume_transfer(&mut self, offset: usize) -> FtpResult<()>

Tell the server to resume the transfer from a certain offset. The offset indicates the amount of bytes to skip from the beginning of the file. the REST command does not actually initiate the transfer. After issuing a REST command, the client must send the appropriate FTP command to transfer the file

It is possible to cancel the REST command, sending a REST command with offset 0

source

pub async fn list(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>

Execute LIST command which returns the detailed file listing in human readable format. If pathname is omited then the list of files in the current directory will be returned otherwise it will the list of files on pathname.

source

pub async fn nlst(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>

Execute NLST command which returns the list of file names only. If pathname is omited then the list of files in the current directory will be returned otherwise it will the list of files on pathname.

source

pub async fn mlsd(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>

Execute MLSD command which returns the machine-processable listing of a directory. If pathname is omited then the list of files in the current directory will be

source

pub async fn mlst(&mut self, pathname: Option<&str>) -> FtpResult<String>

Execute MLST command which returns the machine-processable listing of a file. If pathname is omited then the list of files in the current directory will be

source

pub async fn mdtm<S: AsRef<str>>( &mut self, pathname: S ) -> FtpResult<NaiveDateTime>

Retrieves the modification time of the file at pathname if it exists.

source

pub async fn size<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<usize>

Retrieves the size of the file in bytes at pathname if it exists.

source

pub async fn feat(&mut self) -> FtpResult<Features>

Retrieves the features supported by the server, through the FEAT command.

source

pub async fn opts( &mut self, option: impl ToString, value: Option<impl ToString> ) -> FtpResult<()>

Set option option with an optional value

source

pub async fn site(&mut self, command: impl ToString) -> FtpResult<Response>

Execute a command on the server and return the response

source

pub async fn custom_command( &mut self, command: impl ToString, expected_code: &[Status] ) -> FtpResult<Response>

Perform custom command

source

pub async fn read_response( &mut self, expected_code: Status ) -> FtpResult<Response>

Read response from stream

source

pub async fn read_response_in( &mut self, expected_code: &[Status] ) -> FtpResult<Response>

Retrieve single line response

Auto Trait Implementations§

§

impl<T> Freeze for ImplAsyncFtpStream<T>

§

impl<T> !RefUnwindSafe for ImplAsyncFtpStream<T>

§

impl<T> Send for ImplAsyncFtpStream<T>
where T: Send,

§

impl<T> Sync for ImplAsyncFtpStream<T>
where T: Sync,

§

impl<T> Unpin for ImplAsyncFtpStream<T>

§

impl<T> !UnwindSafe for ImplAsyncFtpStream<T>

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