logo
pub struct FtpStream { /* private fields */ }
Expand description

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

Implementations

Creates an FTP Stream.

Enable active mode for data channel

Set the data channel transfer mode

Set NAT workaround for passive mode

Returns welcome message retrieved from server (if available)

Returns a reference to the underlying TcpStream.

Example:

use suppaftp::FtpStream;
use std::net::TcpStream;
use std::time::Duration;

let stream = FtpStream::connect("127.0.0.1:21")
                       .expect("Couldn't connect to the server...");
stream.get_ref().set_read_timeout(Some(Duration::from_secs(10)))
                .expect("set_read_timeout call failed");
Run

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.

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.

assert!(conn.retr("retr.txt", |stream| {
    let mut buf = Vec::new();
    stream.read_to_end(&mut buf).map(|_|
        assert_eq!(buf, "hello, world!".as_bytes())
    ).map_err(|e| FtpError::ConnectionError(e))
}).is_ok());
Run

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

let cursor = conn.retr_as_buffer("simple_retr.txt").unwrap();
// do something with bytes
assert_eq!(cursor.into_inner(), "hello, world!".as_bytes());
Run

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

Finalize retr stream; must be called once the requested file, got previously with retr_as_stream() has been read

Removes the remote pathname from the server.

Remove the remote file from the server.

This stores a file on the server. r argument must be any struct which implemenents the Read trait. Returns amount of written bytes

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

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

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

Append data from reader to file at filename

abort the previous FTP service command

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

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.

Parse result

You can parse the output of this command with


use std::str::FromStr;
use suppaftp::list::File;

let file: File = File::from_str("-rw-rw-r-- 1 0  1  8192 Nov 5 2018 omar.txt")
    .ok()
    .unwrap();
Run

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.

Retrieves the size of the file in bytes at pathname if it exists.

Trait Implementations

Formats the value using the given formatter. Read more

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.