[][src]Struct async_ftp::FtpStream

pub struct FtpStream { /* fields omitted */ }

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

Implementations

impl FtpStream[src]

pub async fn connect<A: ToSocketAddrs>(addr: A) -> Result<FtpStream>[src]

Creates an FTP Stream.

pub fn get_ref(&self) -> &TcpStream[src]

Returns a reference to the underlying TcpStream.

Example:

use tokio::net::TcpStream;
use std::time::Duration;
use async_ftp::FtpStream;

async {
  let stream = FtpStream::connect("172.25.82.139:21").await
                         .expect("Couldn't connect to the server...");
  let s: &TcpStream = stream.get_ref();
};

pub async fn login<'_, '_, '_>(
    &'_ mut self,
    user: &'_ str,
    password: &'_ str
) -> Result<()>
[src]

Log in to the FTP server.

pub async fn cwd<'_, '_>(&'_ mut self, path: &'_ str) -> Result<()>[src]

Change the current directory to the path specified.

pub async fn cdup<'_>(&'_ mut self) -> Result<()>[src]

Move the current directory to the parent directory.

pub async fn pwd<'_>(&'_ mut self) -> Result<String>[src]

Gets the current directory

pub async fn noop<'_>(&'_ mut self) -> Result<()>[src]

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

pub async fn mkdir<'_, '_>(&'_ mut self, pathname: &'_ str) -> Result<()>[src]

This creates a new directory on the server.

pub async fn transfer_type<'_>(&'_ mut self, file_type: FileType) -> Result<()>[src]

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

pub async fn quit<'_>(&'_ mut self) -> Result<()>[src]

Quits the current FTP session.

pub async fn get<'_, '_>(
    &'_ mut self,
    file_name: &'_ str
) -> Result<BufReader<DataStream>>
[src]

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.

pub async fn rename<'_, '_, '_>(
    &'_ mut self,
    from_name: &'_ str,
    to_name: &'_ str
) -> Result<()>
[src]

Renames the file from_name to to_name

pub async fn retr<'_, '_, F, T, P>(
    &'_ mut self,
    filename: &'_ str,
    reader: F
) -> Result<T> where
    F: Fn(BufReader<DataStream>) -> P,
    P: Future<Output = Result<T>>, 
[src]

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 async_ftp::{FtpStream, DataStream, FtpError};
use tokio::io::{AsyncReadExt, BufReader};
use std::io::Cursor;
async {
  let mut conn = FtpStream::connect("172.25.82.139: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: BufReader<DataStream>) -> 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());
};

pub async fn simple_retr<'_, '_>(
    &'_ mut self,
    file_name: &'_ str
) -> Result<Cursor<Vec<u8>>>
[src]

Simple way to retr a file from the server. This stores the file in memory.

use async_ftp::{FtpStream, FtpError};
use std::io::Cursor;
async {
    let mut conn = FtpStream::connect("172.25.82.139: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 rmdir<'_, '_>(&'_ mut self, pathname: &'_ str) -> Result<()>[src]

Removes the remote pathname from the server.

pub async fn rm<'_, '_>(&'_ mut self, filename: &'_ str) -> Result<()>[src]

Remove the remote file from the server.

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

This stores a file on the server.

pub async fn list<'_, '_>(
    &'_ mut self,
    pathname: Option<&'_ str>
) -> Result<Vec<String>>
[src]

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.

pub async fn nlst<'_, '_>(
    &'_ mut self,
    pathname: Option<&'_ str>
) -> Result<Vec<String>>
[src]

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.

pub async fn mdtm<'_, '_>(
    &'_ mut self,
    pathname: &'_ str
) -> Result<Option<DateTime<Utc>>>
[src]

Retrieves the modification time of the file at pathname if it exists. In case the file does not exist None is returned.

pub async fn size<'_, '_>(
    &'_ mut self,
    pathname: &'_ str
) -> Result<Option<usize>>
[src]

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 read_response<'_>(&'_ mut self, expected_code: u32) -> Result<Line>[src]

pub async fn read_response_in<'_, '_>(
    &'_ mut self,
    expected_code: &'_ [u32]
) -> Result<Line>
[src]

Retrieve single line response

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.