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
impl Client
Sourcepub fn set_mode(&mut self, mode: ClientMode)
pub fn set_mode(&mut self, mode: ClientMode)
Set the mode for the client.
Sourcepub fn connect(
hostname: &str,
user: &str,
password: &str,
) -> Result<Self, Error>
pub fn connect( hostname: &str, user: &str, password: &str, ) -> Result<Self, Error>
Connect to a new FTP server using plain text (no TLS).
Sourcepub fn connect_tls(
hostname: &str,
user: &str,
password: &str,
) -> Result<Self, Error>
pub fn connect_tls( hostname: &str, user: &str, password: &str, ) -> Result<Self, Error>
Connect to a new FTP server using a secure connection (TLS).
Sourcepub fn connect_tls_with_port(
hostname: &str,
port: u32,
user: &str,
password: &str,
) -> Result<Self, Error>
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.
Sourcepub fn connect_with_port(
hostname: &str,
port: u32,
user: &str,
password: &str,
) -> Result<Self, Error>
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.
Sourcepub fn get_welcome(&self) -> Option<&String>
pub fn get_welcome(&self) -> Option<&String>
Get the welcome message sent by the server at the connection establishment.
Sourcepub fn login(&mut self, user: &str, password: &str) -> Result<(), Error>
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”).
Sourcepub fn cwd(&mut self, dir: &str) -> Result<(), Error>
pub fn cwd(&mut self, dir: &str) -> Result<(), Error>
Change the working directory on the current session.
Sourcepub fn cdup(&mut self) -> Result<(), Error>
pub fn cdup(&mut self) -> Result<(), Error>
Go up to the parent directory on the current session.
Sourcepub fn help(&mut self) -> Result<(), Error>
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.
Sourcepub fn noop(&mut self) -> Result<(), Error>
pub fn noop(&mut self) -> Result<(), Error>
This command should not do anything other than receiving an OK response from the server.
Sourcepub fn status(&mut self) -> Result<String, Error>
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.
Sourcepub fn list(&mut self, path: &str) -> Result<String, Error>
pub fn list(&mut self, path: &str) -> Result<String, Error>
List the provided path in any way the server desires.
Sourcepub fn list_names(&mut self, path: &str) -> Result<Vec<String>, Error>
pub fn list_names(&mut self, path: &str) -> Result<Vec<String>, Error>
List the provided path, providing only name information about files and directories.
Sourcepub fn store<B: AsRef<[u8]>>(
&mut self,
path: &str,
data: B,
) -> Result<(), Error>
pub fn store<B: AsRef<[u8]>>( &mut self, path: &str, data: B, ) -> Result<(), Error>
Store a new file on a provided path and name.
Sourcepub fn store_unique<B: AsRef<[u8]>>(&mut self, data: B) -> Result<String, Error>
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.
Sourcepub fn append<B: AsRef<[u8]>>(
&mut self,
path: &str,
data: B,
) -> Result<(), Error>
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.
Sourcepub fn allocate(
&mut self,
_logical_size: usize,
_logical_page_size: Option<usize>,
) -> Result<(), Error>
pub fn allocate( &mut self, _logical_size: usize, _logical_page_size: Option<usize>, ) -> Result<(), Error>
Preallocate space on the server. Unimplemented.
Sourcepub fn rename_file(
&mut self,
path_from: &str,
path_to: &str,
) -> Result<(), Error>
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.
Sourcepub fn remove_directory(&mut self, dir_path: &str) -> Result<(), Error>
pub fn remove_directory(&mut self, dir_path: &str) -> Result<(), Error>
Remove an existing directory.
Sourcepub fn site_parameters(&mut self) -> Result<String, Error>
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.
Sourcepub fn system(&mut self) -> Result<String, Error>
pub fn system(&mut self) -> Result<String, Error>
Get the type of operating system on the server.
Sourcepub fn retrieve_file(&mut self, path: &str) -> Result<Vec<u8>, Error>
pub fn retrieve_file(&mut self, path: &str) -> Result<Vec<u8>, Error>
Download a file at a path into a byte buffer.
Sourcepub fn get_data_connection(&mut self) -> Result<BufReader<TcpStream>, Error>
pub fn get_data_connection(&mut self) -> Result<BufReader<TcpStream>, Error>
Acquire the data connection using the current ClientMode.
Sourcepub fn extended_passive_mode_connection(
&mut self,
) -> Result<BufReader<TcpStream>, Error>
pub fn extended_passive_mode_connection( &mut self, ) -> Result<BufReader<TcpStream>, Error>
Create a extended passive mode connection.
Sourcepub fn passive_mode_connection(&mut self) -> Result<BufReader<TcpStream>, Error>
pub fn passive_mode_connection(&mut self) -> Result<BufReader<TcpStream>, Error>
Create a passive mode connection.
Sourcepub fn write_unary_command_expecting(
&mut self,
cmd: &str,
arg: &str,
valid_statuses: Vec<StatusCodeKind>,
) -> Result<ServerResponse, Error>
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.
Sourcepub fn write_unary_command(&mut self, cmd: &str, arg: &str) -> Result<(), Error>
pub fn write_unary_command(&mut self, cmd: &str, arg: &str) -> Result<(), Error>
Write a command with one argument to the server.
Sourcepub fn write_command_expecting(
&mut self,
cmd: &str,
valid_statuses: Vec<StatusCodeKind>,
) -> Result<ServerResponse, Error>
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.
Sourcepub fn parse_reply_expecting(
&mut self,
valid_statuses: Vec<StatusCodeKind>,
) -> Result<ServerResponse, Error>
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.
Sourcepub fn parse_reply(&mut self) -> Result<ServerResponse, Error>
pub fn parse_reply(&mut self) -> Result<ServerResponse, Error>
Parse the server reply into a ServerResponse.
Sourcepub fn read_reply(&mut self) -> Result<String, Error>
pub fn read_reply(&mut self) -> Result<String, Error>
Read the server reply as a raw string.