Crate suppaftp[−][src]
Expand description
SuppaFTP
SuppaFTP is an FTP client library written in Rust with optional FTPS support. You can choose whether to use sync or async version of this library using cargo.toml features. SuppaFTP is a library derived from rust-ftp, which has many additional features though, such as:
- New methods to work with streams when transferring files, to give you complete freedom when you work with file transfers
- Method to retrieve the welcome message
- Supports for both sync and async rust
- Some extra features, such as the parser for the LIST command output
- Replaced openssl with native-tls to make it compatible with all the operating system (without forcing users to install openssl).
- All the old statements have been replaced with modern rust
- Better error handling and possibility to retrieve error codes
- Test units and high code coverage to provide the community with a reliable library
Get started
First of you need to add suppaftp to your project dependencies:
suppaftp = "4.1.2"
If you want to enable TLS support to work with FTPS you need to enable the secure feature in your dependencies:
suppaftp = { version = "4.1.2", features = ["secure"] }
While if you want to go async, then you must enable the async feature or if you want to mix secure and async then there is the super feature async-secure!
suppaftp = { version = "4.1.2", features = ["async"] }
suppaftp = { version = "4.1.2", features = ["async-secure"] }
Keep in mind that you can’t use the sync and the async version of this library at the same time!
Usage
Here is a basic usage example:
use suppaftp::FtpStream;
let mut ftp_stream = FtpStream::connect("127.0.0.1:10021").unwrap_or_else(|err|
panic!("{}", err)
);
assert!(ftp_stream.login("test", "test").is_ok());
// Disconnect from server
assert!(ftp_stream.quit().is_ok());
RunFTPS
The client supports FTPS on demand. To enable it the client should be
compiled with feature secure
enabled which requires
rust-native-tls.
The client uses explicit mode for connecting FTPS what means you should connect the server as usually and then switch to the secure mode (TLS is used). For better security it’s the good practice to switch to the secure mode before authentication.
FTPS Usage
use suppaftp::FtpStream;
use suppaftp::native_tls::{TlsConnector, TlsStream};
let ftp_stream = FtpStream::connect("test.rebex.net:21").unwrap();
// Switch to the secure mode
let mut ftp_stream = ftp_stream.into_secure(TlsConnector::new().unwrap(), "test.rebex.net").unwrap();
ftp_stream.login("demo", "password").unwrap();
// Do other secret stuff
// Switch back to the insecure mode (if required)
let mut ftp_stream = ftp_stream.into_insecure().unwrap();
// Do all public stuff
assert!(ftp_stream.quit().is_ok());
RunGoing async
SuppaFTP also supports async execution as said before, through the async feature. Basically there’s no difference in the function you can use when using the async version of suppaftp. Let’s quickly see in the example how it works
use suppaftp::FtpStream;
use suppftp::async_native_tls::{TlsConnector, TlsStream};
let ftp_stream = FtpStream::connect("test.rebex.net:21").await.unwrap();
// Switch to the secure mode
let mut ftp_stream = ftp_stream.into_secure(TlsConnector::new(), "test.rebex.net").await.unwrap();
ftp_stream.login("demo", "password").await.unwrap();
// Do other secret stuff
// Do all public stuff
assert!(ftp_stream.quit().await.is_ok());
RunRe-exports
pub use types::FtpError;
Modules
Structs
FtpStream