Struct async_ftp::FtpStream[][src]

pub struct FtpStream { /* fields omitted */ }
Expand description

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

Implementations

Creates an FTP Stream.

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

Get welcome message from the server on connect.

Log in to the FTP server.

Change the current directory to the path specified.

Move the current directory to the parent directory.

Gets the current directory

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

This creates a new directory on the server.

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

Quits the current FTP session.

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

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.

Renames the file from_name to to_name

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

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

Removes the remote pathname from the server.

Remove the remote file from the server.

This stores a file on the server.

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.

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.

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

Retrieves the size of the file in bytes at pathname if it exists. In case the file does not exist None is returned.

Retrieve single line response

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.