Struct FtpClient

Source
pub struct FtpClient { /* private fields */ }

Implementations§

Source§

impl FtpClient

Source

pub fn init_default(&mut self)

Source

pub async fn connect<A: ToSocketAddrs>(addr: A) -> Result<FtpClient>

Creates an FTP Client.

Source

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();
};
Source

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

Get welcome message from the server on connect.

Source

pub async fn login(&mut self, user: &str, password: &str) -> Result<bool>

Log in to the FTP server.

Source

pub async fn cwd(&mut self, path: &str) -> Result<bool>

Change the current Directory to the path specified.

Source

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

Move the current Directory to the parent Directory.

Source

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

Gets the current Directory

Source

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

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

Source

pub async fn make_directory(&mut self, pathname: &str) -> Result<bool>

This creates a new Directory on the server.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

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.

Source

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.

Source

pub async fn logout(&mut self) -> Result<bool>

Quits the current FTP session.

Source

pub async fn restart_from(&mut self, offset: u64) -> Result<bool>

Sets the byte from which the transfer is to be restarted.

Source

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.

Source

pub async fn rename(&mut self, from_name: &str, to_name: &str) -> Result<bool>

Renames the File from_name to to_name

Source

pub async fn retr<F, T, P, E>( &mut self, filename: &str, reader: F, ) -> Result<T, E>
where F: Fn(BufStream<Connection>) -> P, P: Future<Output = Result<T, E>>, E: From<FtpError>,

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());
};
Source

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>(())
};
Source

pub async fn remove_directory(&mut self, pathname: &str) -> Result<bool>

Source

pub async fn rmd(&mut self, pathname: &str) -> Result<u32>

Removes the remote pathname from the server.

Source

pub async fn delete_file(&mut self, filename: &str) -> Result<bool>

Source

pub async fn dele(&mut self, filename: &str) -> Result<u32>

Remove the remote File from the server.

Source

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.

Source

pub async fn put<R: AsyncRead + Unpin>( &mut self, filename: &str, r: &mut R, ) -> Result<()>

This stores a File on the server.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn feat(&mut self) -> Result<u32>

Source

pub async fn features(&mut self, cmd: Command) -> Result<Option<Vec<String>>>

Source

pub fn check_response(&mut self, expected_code: u32) -> Result<()>

Source

pub fn check_response_in(&mut self, expected_code: &[u32]) -> Result<()>

Retrieve single line response

Auto Trait Implementations§

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

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.