pub struct FtpClient { /* private fields */ }
Implementations§
Source§impl FtpClient
impl FtpClient
pub fn init_default(&mut self)
Sourcepub async fn connect<A: ToSocketAddrs>(addr: A) -> Result<FtpClient>
pub async fn connect<A: ToSocketAddrs>(addr: A) -> Result<FtpClient>
Creates an FTP Client.
Sourcepub fn get_ref(&self) -> &TcpStream
pub fn get_ref(&self) -> &TcpStream
Returns a reference to the underlying TcpStream.
Example:
use tokio::net::TcpStream;
use std::time::Duration;
use ftp_rs::FtpClient;
async {
let client = FtpClient::connect("192.168.32.204:21").await
.expect("Couldn't connect to the server...");
let s: &TcpStream = client.get_ref();
};
Sourcepub fn get_welcome_msg(&self) -> Option<&str>
pub fn get_welcome_msg(&self) -> Option<&str>
Get welcome message from the server on connect.
Sourcepub async fn login(&mut self, user: &str, password: &str) -> Result<bool>
pub async fn login(&mut self, user: &str, password: &str) -> Result<bool>
Log in to the FTP server.
Sourcepub async fn cwd(&mut self, path: &str) -> Result<bool>
pub async fn cwd(&mut self, path: &str) -> Result<bool>
Change the current Directory to the path specified.
Sourcepub async fn cdup(&mut self) -> Result<bool>
pub async fn cdup(&mut self) -> Result<bool>
Move the current Directory to the parent Directory.
Sourcepub async fn noop(&mut self) -> Result<bool>
pub async fn noop(&mut self) -> Result<bool>
This does nothing. This is usually just used to keep the connection open.
Sourcepub async fn make_directory(&mut self, pathname: &str) -> Result<bool>
pub async fn make_directory(&mut self, pathname: &str) -> Result<bool>
This creates a new Directory on the server.
Sourcepub async fn mkd(&mut self, pathname: &str) -> Result<u32>
pub async fn mkd(&mut self, pathname: &str) -> Result<u32>
A convenience method to send the FTP MKD command to the server, receive the reply, and return the reply code.
Sourcepub async fn acct(&mut self, account: &str) -> Result<u32>
pub async fn acct(&mut self, account: &str) -> Result<u32>
A convenience method to send the FTP ACCT command to the server, receive the reply, and return the reply code.
Sourcepub async fn abor(&mut self) -> Result<u32>
pub async fn abor(&mut self) -> Result<u32>
A convenience method to send the FTP ABOR command to the server, receive the reply, and return the reply code.
Sourcepub async fn rein(&mut self) -> Result<u32>
pub async fn rein(&mut self) -> Result<u32>
A convenience method to send the FTP REIN command to the server, receive the reply, and return the reply code.
Sourcepub async fn smnt(&mut self, dir: &str) -> Result<u32>
pub async fn smnt(&mut self, dir: &str) -> Result<u32>
A convenience method to send the FTP SMNT command to the server, receive the reply, and return the reply code.
Sourcepub async fn epsv(&mut self) -> Result<u32>
pub async fn epsv(&mut self) -> Result<u32>
A convenience method to send the FTP EPSV command to the server, receive the reply, and return the reply code.
Sourcepub async fn type_cmd(&mut self, file_type: u32) -> Result<u32>
pub async fn type_cmd(&mut self, file_type: u32) -> Result<u32>
A convenience method to send the FTP TYPE command to the server, receive the reply, and return the reply code.
Sourcepub async fn stru(&mut self, structure: u32) -> Result<u32>
pub async fn stru(&mut self, structure: u32) -> Result<u32>
A convenience method to send the FTP STRU command to the server, receive the reply, and return the reply code.
Sourcepub async fn mode(&mut self, mode: u32) -> Result<u32>
pub async fn mode(&mut self, mode: u32) -> Result<u32>
A convenience method to send the FTP MODE command to the server, receive the reply, and return the reply code.
Sourcepub async fn stou(&mut self) -> Result<u32>
pub async fn stou(&mut self) -> Result<u32>
A convenience method to send the FTP STOU command to the server, receive the reply, and return the reply code.
Sourcepub async fn stou_pathname(&mut self, pathname: &str) -> Result<u32>
pub async fn stou_pathname(&mut self, pathname: &str) -> Result<u32>
A convenience method to send the FTP STOU command to the server, receive the reply, and return the reply code.
Sourcepub async fn appe(&mut self, pathname: &str) -> Result<u32>
pub async fn appe(&mut self, pathname: &str) -> Result<u32>
A convenience method to send the FTP APPE command to the server, receive the reply, and return the reply code.
Sourcepub async fn allo(&mut self, bytes: u32) -> Result<u32>
pub async fn allo(&mut self, bytes: u32) -> Result<u32>
A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.
Sourcepub async fn allo_record_size(
&mut self,
bytes: u32,
record_size: u32,
) -> Result<u32>
pub async fn allo_record_size( &mut self, bytes: u32, record_size: u32, ) -> Result<u32>
A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.
Sourcepub async fn port(&mut self, host: IpAddr, port: u16) -> Result<u32>
pub async fn port(&mut self, host: IpAddr, port: u16) -> Result<u32>
A convenience method to send the FTP PORT command to the server, receive the reply, and return the reply code.
Sourcepub async fn eprt(&mut self, host: IpAddr, port: u16) -> Result<u32>
pub async fn eprt(&mut self, host: IpAddr, port: u16) -> Result<u32>
A convenience method to send the FTP EPRT command to the server, receive the reply, and return the reply code.
- EPRT |1|132.235.1.2|6275|
- EPRT |2|1080::8:800:200C:417A|5282|
Sourcepub async fn mfmt(&mut self, pathname: &str, timeval: &str) -> Result<u32>
pub async fn mfmt(&mut self, pathname: &str, timeval: &str) -> Result<u32>
A convenience method to send the FTP MFMT command to the server, receive the reply, and return the reply code.
Sourcepub async fn transfer_type(&mut self, file_type: FileType) -> Result<bool>
pub async fn transfer_type(&mut self, file_type: FileType) -> Result<bool>
Sets the type of File to be transferred. That is the implementation
of TYPE
command.
Sourcepub async fn restart_from(&mut self, offset: u64) -> Result<bool>
pub async fn restart_from(&mut self, offset: u64) -> Result<bool>
Sets the byte from which the transfer is to be restarted.
Sourcepub async fn get(&mut self, file_name: &str) -> Result<BufStream<Connection>>
pub async fn get(&mut self, file_name: &str) -> Result<BufStream<Connection>>
Retrieves the File name specified from the server. 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.
Sourcepub async fn rename(&mut self, from_name: &str, to_name: &str) -> Result<bool>
pub async fn rename(&mut self, from_name: &str, to_name: &str) -> Result<bool>
Renames the File from_name to to_name
Sourcepub async fn retr<F, T, P, E>(
&mut self,
filename: &str,
reader: F,
) -> Result<T, E>
pub async fn retr<F, T, P, E>( &mut self, filename: &str, reader: F, ) -> Result<T, E>
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.
use ftp_rs::{FtpClient, Connection, FtpError};
use tokio::io::{AsyncReadExt, BufStream};
use std::io::Cursor;
async {
let mut conn = FtpClient::connect("192.168.32.204:21").await.unwrap();
conn.login("Doe", "mumble").await.unwrap();
let mut reader = Cursor::new("hello, world!".as_bytes());
conn.put("retr.txt", &mut reader).await.unwrap();
async fn lambda(mut reader: BufStream<Connection>) -> Result<Vec<u8>, FtpError> {
let mut buffer = Vec::new();
reader
.read_to_end(&mut buffer)
.await
.map_err(FtpError::ConnectionError)?;
assert_eq!(buffer, "hello, world!".as_bytes());
Ok(buffer)
};
assert!(conn.retr("retr.txt", lambda).await.is_ok());
assert!(conn.rm("retr.txt").await.is_ok());
};
Sourcepub async fn simple_retr(&mut self, file_name: &str) -> Result<Cursor<Vec<u8>>>
pub async fn simple_retr(&mut self, file_name: &str) -> Result<Cursor<Vec<u8>>>
Simple way to retr a File from the server. This stores the File in memory.
use ftp_rs::{FtpClient, FtpError};
use std::io::Cursor;
async {
let mut conn = FtpClient::connect("192.168.32.204:21").await?;
conn.login("Doe", "mumble").await?;
let mut reader = Cursor::new("hello, world!".as_bytes());
conn.put("simple_retr.txt", &mut reader).await?;
let cursor = conn.simple_retr("simple_retr.txt").await?;
assert_eq!(cursor.into_inner(), "hello, world!".as_bytes());
assert!(conn.rm("simple_retr.txt").await.is_ok());
Ok::<(), FtpError>(())
};
pub async fn remove_directory(&mut self, pathname: &str) -> Result<bool>
Sourcepub async fn rmd(&mut self, pathname: &str) -> Result<u32>
pub async fn rmd(&mut self, pathname: &str) -> Result<u32>
Removes the remote pathname from the server.
pub async fn delete_file(&mut self, filename: &str) -> Result<bool>
Sourcepub async fn dele(&mut self, filename: &str) -> Result<u32>
pub async fn dele(&mut self, filename: &str) -> Result<u32>
Remove the remote File from the server.
Sourcepub async fn send_command(
&mut self,
cmd: Command,
agrs: Option<&str>,
) -> Result<u32>
pub async fn send_command( &mut self, cmd: Command, agrs: Option<&str>, ) -> Result<u32>
Sends an FTP command to the server, waits for a reply and returns the numerical response code.
Sourcepub async fn put<R: AsyncRead + Unpin>(
&mut self,
filename: &str,
r: &mut R,
) -> Result<()>
pub async fn put<R: AsyncRead + Unpin>( &mut self, filename: &str, r: &mut R, ) -> Result<()>
This stores a File on the server.
Sourcepub async fn list(&mut self, pathname: Option<&str>) -> Result<Vec<String>>
pub async fn list(&mut self, pathname: Option<&str>) -> Result<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>) -> Result<Vec<String>>
pub async fn nlst(&mut self, pathname: Option<&str>) -> Result<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 mdtm(&mut self, pathname: &str) -> Result<Option<DateTime<Utc>>>
pub async fn mdtm(&mut self, pathname: &str) -> Result<Option<DateTime<Utc>>>
Retrieves the modification time of the File at pathname
if it exists.
In case the File does not exist None
is returned.
Sourcepub async fn size(&mut self, pathname: &str) -> Result<Option<usize>>
pub async fn size(&mut self, pathname: &str) -> Result<Option<usize>>
Retrieves the size of the File in bytes at pathname
if it exists.
In case the File does not exist None
is returned.
pub async fn feat(&mut self) -> Result<u32>
pub async fn features(&mut self, cmd: Command) -> Result<Option<Vec<String>>>
pub fn check_response(&mut self, expected_code: u32) -> Result<()>
Sourcepub fn check_response_in(&mut self, expected_code: &[u32]) -> Result<()>
pub fn check_response_in(&mut self, expected_code: &[u32]) -> Result<()>
Retrieve single line response