FTP client for Rust
FTPS support is disabled by default. To enable it secure
should be activated in Cargo.toml
.
toml
[dependencies]
async_ftp = { version = "<version>", features = ["secure"] }
```rust use std::str; use std::io::Cursor; use async_ftp::FtpStream;
async fn asyncmain() -> Result<(), Box
// Get the current directory that the client will be reading from and writing to.
println!("Current directory: {}", ftp_stream.pwd().await?);
// Change into a new directory, relative to the one we are currently in.
let _ = ftp_stream.cwd("test_data").await?;
// Retrieve (GET) a file from the FTP server in the current working directory.
let remote_file = ftp_stream.simple_retr("ftpext-charter.txt").await?;
println!("Read file with contents\n{}\n", str::from_utf8(&remote_file.into_inner()).await?);
// Store (PUT) a file from the client to the current working directory of the server.
let mut reader = Cursor::new("Hello from the Rust \"ftp\" crate!".as_bytes());
let _ = ftp_stream.put("greeting.txt", &mut reader).await?;
println!("Successfully wrote greeting.txt");
// Terminate the connection to the server.
let _ = ftp_stream.quit();
}
fn main() -> Result<(), Box
```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
All you need to develop rust-ftp and run the tests is Rust and Docker.
The tests
folder contains a Dockerfile
that installs and configures
the vsftpd server.
To create the Docker image:
bash
docker build -t ftp-server tests
To start the FTP server that is tested against:
bash
tests/ftp-server.sh
This script runs the ftp-server
image in detached mode and starts the vsftpd
daemon. It binds ports 21 (FTP) as well as the range 65000-65010 for passive connections.
Once you have an instance running, to run tests type:
bash
cargo test
The following commands can be useful: ```bash
docker ps --filter ancestor=ftp-server
docker stop containername docker rm containername
docker rmi ftp-server ```