Struct suppaftp::ImplAsyncFtpStream
source · pub struct ImplAsyncFtpStream<T>where
T: AsyncTlsStream,{ /* private fields */ }
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,
impl<T> ImplAsyncFtpStream<T>where
T: AsyncTlsStream,
pub async fn connect<A: ToSocketAddrs>(addr: A) -> FtpResult<Self>
sourcepub async fn connect_timeout(
addr: SocketAddr,
timeout: Duration
) -> FtpResult<Self>
pub async fn connect_timeout( addr: SocketAddr, timeout: Duration ) -> FtpResult<Self>
Try to connect to the remote server but with the specified timeout
sourcepub async fn connect_with_stream(stream: TcpStream) -> FtpResult<Self>
pub async fn connect_with_stream(stream: TcpStream) -> FtpResult<Self>
Connect using provided configured tcp stream
sourcepub 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.
pub async fn into_secure( self, tls_connector: impl AsyncTlsConnector<Stream = T> + Send + Sync + 'static, domain: &str ) -> FtpResult<Self>
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();
Runsourcepub 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.
pub async fn connect_secure_implicit<A: ToSocketAddrs>( addr: A, tls_connector: impl AsyncTlsConnector<Stream = T> + Send + Sync + 'static, domain: &str ) -> FtpResult<Self>
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();
Runsourcepub fn active_mode(self, listener_timeout: Duration) -> Self
pub fn active_mode(self, listener_timeout: Duration) -> Self
Enable active mode for data channel
sourcepub fn get_welcome_msg(&self) -> Option<&str>
pub fn get_welcome_msg(&self) -> Option<&str>
Returns welcome message retrieved from server (if available)
sourcepub fn set_passive_nat_workaround(&mut self, nat_workaround: bool)
pub fn set_passive_nat_workaround(&mut self, nat_workaround: bool)
Set NAT workaround for passive mode
sourcepub async fn login<S: AsRef<str>>(
&mut self,
user: S,
password: S
) -> FtpResult<()>
pub async fn login<S: AsRef<str>>( &mut self, user: S, password: S ) -> FtpResult<()>
Log in to the FTP server.
sourcepub async fn clear_command_channel(self) -> FtpResult<Self>
Available on crate feature async-secure
only.
pub async fn clear_command_channel(self) -> FtpResult<Self>
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.
sourcepub async fn cwd<S: AsRef<str>>(&mut self, path: S) -> FtpResult<()>
pub async fn cwd<S: AsRef<str>>(&mut self, path: S) -> FtpResult<()>
Change the current directory to the path specified.
sourcepub async fn cdup(&mut self) -> FtpResult<()>
pub async fn cdup(&mut self) -> FtpResult<()>
Move the current directory to the parent directory.
sourcepub async fn noop(&mut self) -> FtpResult<()>
pub async fn noop(&mut self) -> FtpResult<()>
This does nothing. This is usually just used to keep the connection open.
sourcepub async fn eprt(&mut self, address: SocketAddr) -> FtpResult<()>
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
sourcepub async fn mkdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>
pub async fn mkdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>
This creates a new directory on the server.
sourcepub async fn transfer_type(&mut self, file_type: FileType) -> FtpResult<()>
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.
sourcepub async fn rename<S: AsRef<str>>(
&mut self,
from_name: S,
to_name: S
) -> FtpResult<()>
pub async fn rename<S: AsRef<str>>( &mut self, from_name: S, to_name: S ) -> FtpResult<()>
Renames the file from_name to to_name
sourcepub async fn retr<S, F, U>(&mut self, file_name: S, reader: F) -> FtpResult<U>
pub async fn retr<S, F, U>(&mut self, file_name: S, reader: F) -> FtpResult<U>
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.
sourcepub async fn retr_as_stream<S: AsRef<str>>(
&mut self,
file_name: S
) -> FtpResult<DataStream<T>>
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()
sourcepub async fn finalize_retr_stream(&mut self, stream: impl Read) -> FtpResult<()>
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
sourcepub async fn rmdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>
pub async fn rmdir<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<()>
Removes the remote pathname from the server.
sourcepub async fn rm<S: AsRef<str>>(&mut self, filename: S) -> FtpResult<()>
pub async fn rm<S: AsRef<str>>(&mut self, filename: S) -> FtpResult<()>
Remove the remote file from the server.
sourcepub async fn put_file<S, R>(&mut self, filename: S, r: &mut R) -> FtpResult<u64>
pub async fn put_file<S, R>(&mut self, filename: S, r: &mut R) -> FtpResult<u64>
This stores a file on the server. r argument must be any struct which implemenents the Read trait
sourcepub async fn put_with_stream<S: AsRef<str>>(
&mut self,
filename: S
) -> FtpResult<DataStream<T>>
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
sourcepub async fn finalize_put_stream(
&mut self,
stream: impl Write + Unpin
) -> FtpResult<()>
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
sourcepub async fn append_with_stream<S: AsRef<str>>(
&mut self,
filename: S
) -> FtpResult<DataStream<T>>
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
sourcepub async fn append_file<R>(
&mut self,
filename: &str,
r: &mut R
) -> FtpResult<u64>
pub async fn append_file<R>( &mut self, filename: &str, r: &mut R ) -> FtpResult<u64>
Append data from reader to file at filename
sourcepub async fn abort<R>(&mut self, data_stream: R) -> FtpResult<()>
pub async fn abort<R>(&mut self, data_stream: R) -> FtpResult<()>
abort the previous FTP service command
sourcepub async fn resume_transfer(&mut self, offset: usize) -> FtpResult<()>
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
sourcepub async fn list(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>
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
.
sourcepub async fn nlst(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>
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
.
sourcepub async fn mlsd(&mut self, pathname: Option<&str>) -> FtpResult<Vec<String>>
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
sourcepub async fn mlst(&mut self, pathname: Option<&str>) -> FtpResult<String>
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
sourcepub async fn mdtm<S: AsRef<str>>(
&mut self,
pathname: S
) -> FtpResult<NaiveDateTime>
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.
sourcepub async fn size<S: AsRef<str>>(&mut self, pathname: S) -> FtpResult<usize>
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.
sourcepub async fn feat(&mut self) -> FtpResult<Features>
pub async fn feat(&mut self) -> FtpResult<Features>
Retrieves the features supported by the server, through the FEAT command.
sourcepub async fn opts(
&mut self,
option: impl ToString,
value: Option<impl ToString>
) -> FtpResult<()>
pub async fn opts( &mut self, option: impl ToString, value: Option<impl ToString> ) -> FtpResult<()>
Set option option
with an optional value
sourcepub async fn site(&mut self, command: impl ToString) -> FtpResult<Response>
pub async fn site(&mut self, command: impl ToString) -> FtpResult<Response>
Execute a command on the server and return the response
sourcepub async fn custom_command(
&mut self,
command: impl ToString,
expected_code: &[Status]
) -> FtpResult<Response>
pub async fn custom_command( &mut self, command: impl ToString, expected_code: &[Status] ) -> FtpResult<Response>
Perform custom command
sourcepub async fn read_response(
&mut self,
expected_code: Status
) -> FtpResult<Response>
pub async fn read_response( &mut self, expected_code: Status ) -> FtpResult<Response>
Read response from stream
sourcepub async fn read_response_in(
&mut self,
expected_code: &[Status]
) -> FtpResult<Response>
pub async fn read_response_in( &mut self, expected_code: &[Status] ) -> FtpResult<Response>
Retrieve single line response