Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

The Client is where most of the functionality is, it keeps a control connection open and opens up data connections as commands are issued. This struct is a very thin wrapper over the FTP protocol.

Implementations§

Source§

impl Client

Source

pub fn set_mode(&mut self, mode: ClientMode)

Set the mode for the client.

Source

pub fn connect( hostname: &str, user: &str, password: &str, ) -> Result<Self, Error>

Connect to a new FTP server using plain text (no TLS).

Source

pub fn connect_tls( hostname: &str, user: &str, password: &str, ) -> Result<Self, Error>

Connect to a new FTP server using a secure connection (TLS).

Source

pub fn connect_tls_with_port( hostname: &str, port: u32, user: &str, password: &str, ) -> Result<Self, Error>

Connect to a new FTP server using a secure connection (TLS) on a specific port.

Source

pub fn connect_with_port( hostname: &str, port: u32, user: &str, password: &str, ) -> Result<Self, Error>

Connect to a new FTP server using plain text (no TLS) on a specific port.

Source

pub fn get_welcome(&self) -> Option<&String>

Get the welcome message sent by the server at the connection establishment.

Source

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

Login using the given user and password. Note that many servers require a login with an anonymous user, such as client.login(“anonymous”, “anonymous@mail.com”).

Source

pub fn logout(&mut self) -> Result<(), Error>

Logout from the current user/password pair.

Source

pub fn cwd(&mut self, dir: &str) -> Result<(), Error>

Change the working directory on the current session.

Source

pub fn cdup(&mut self) -> Result<(), Error>

Go up to the parent directory on the current session.

Source

pub fn help(&mut self) -> Result<(), Error>

Show server information regarding its implementation status to the user.

The help command can also be used with an argument to see detailed information about a single command, this behaviour is not implemented.

Source

pub fn noop(&mut self) -> Result<(), Error>

This command should not do anything other than receiving an OK response from the server.

Source

pub fn ascii(&mut self) -> Result<(), Error>

Set the transfer type to ascii

Source

pub fn binary(&mut self) -> Result<(), Error>

Set the transfer type to binary

Source

pub fn status(&mut self) -> Result<String, Error>

Get the current reported status from the server. This can be used during transfer and between them. This command can be used with and argument to get behaviour similar to LIST, this particular behaviour is not implemented.

Source

pub fn list(&mut self, path: &str) -> Result<String, Error>

List the provided path in any way the server desires.

Source

pub fn list_names(&mut self, path: &str) -> Result<Vec<String>, Error>

List the provided path, providing only name information about files and directories.

Source

pub fn store<B: AsRef<[u8]>>( &mut self, path: &str, data: B, ) -> Result<(), Error>

Store a new file on a provided path and name.

Source

pub fn store_unique<B: AsRef<[u8]>>(&mut self, data: B) -> Result<String, Error>

Store a new file on a provided path using a random unique name.

Source

pub fn append<B: AsRef<[u8]>>( &mut self, path: &str, data: B, ) -> Result<(), Error>

Append to a existing file or a create a new one.

Source

pub fn restart(&mut self) -> Result<(), Error>

Restart a file transfer. Unimplemented.

Source

pub fn abort(&mut self) -> Result<(), Error>

Abort a file transfer. Unimplemented.

Source

pub fn allocate( &mut self, _logical_size: usize, _logical_page_size: Option<usize>, ) -> Result<(), Error>

Preallocate space on the server. Unimplemented.

Source

pub fn rename_file( &mut self, path_from: &str, path_to: &str, ) -> Result<(), Error>

Move a file from a path to another, essentially renaming it.

Source

pub fn remove_directory(&mut self, dir_path: &str) -> Result<(), Error>

Remove an existing directory.

Source

pub fn make_directory(&mut self, dir_path: &str) -> Result<(), Error>

Make a new directory.

Source

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

Get the current working directory.

Source

pub fn site_parameters(&mut self) -> Result<String, Error>

This command is used by the server to provide services specific to his system that are essential to file transfer but not sufficiently universal to be included as commands in the protocol.

The nature of these services and the specification of their syntax can be stated in a reply to the HELP SITE command.

Extracted from RFC959.

Source

pub fn system(&mut self) -> Result<String, Error>

Get the type of operating system on the server.

Source

pub fn delete_file(&mut self, dir_path: &str) -> Result<(), Error>

Delete a file at a path.

Source

pub fn retrieve_file(&mut self, path: &str) -> Result<Vec<u8>, Error>

Download a file at a path into a byte buffer.

Source

pub fn get_data_connection(&mut self) -> Result<BufReader<TcpStream>, Error>

Acquire the data connection using the current ClientMode.

Source

pub fn extended_passive_mode_connection( &mut self, ) -> Result<BufReader<TcpStream>, Error>

Create a extended passive mode connection.

Source

pub fn passive_mode_connection(&mut self) -> Result<BufReader<TcpStream>, Error>

Create a passive mode connection.

Source

pub fn write_unary_command_expecting( &mut self, cmd: &str, arg: &str, valid_statuses: Vec<StatusCodeKind>, ) -> Result<ServerResponse, Error>

Write a command with one argument to the server expecting a list of positive status codes.

Source

pub fn write_unary_command(&mut self, cmd: &str, arg: &str) -> Result<(), Error>

Write a command with one argument to the server.

Source

pub fn write_command_expecting( &mut self, cmd: &str, valid_statuses: Vec<StatusCodeKind>, ) -> Result<ServerResponse, Error>

Write a command to the server expecting a list of positive status codes.

Source

pub fn write_command(&mut self, cmd: &str) -> Result<(), Error>

Write a command to the server.

Source

pub fn parse_reply_expecting( &mut self, valid_statuses: Vec<StatusCodeKind>, ) -> Result<ServerResponse, Error>

Parse the server reply into a ServerResponse expecting a list of status codes.

Source

pub fn parse_reply(&mut self) -> Result<ServerResponse, Error>

Parse the server reply into a ServerResponse.

Source

pub fn read_reply(&mut self) -> Result<String, Error>

Read the server reply as a raw string.

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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.