mirror of
https://github.com/dani-garcia/rust_async_ftp.git
synced 2026-11-02 10:17:14 +09:00
- Added function to get server welcome message. - Use the peer address when the server responds with all zeroes like is the case with IPv6. - Added some small tests for types - Make the test results clearer, using ? instead of asserting is_ok()
46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
use async_ftp::{FtpError, FtpStream};
|
|
#[cfg(test)]
|
|
use std::io::Cursor;
|
|
|
|
#[test]
|
|
fn test_ftp() {
|
|
let future = async {
|
|
let mut ftp_stream = FtpStream::connect("192.168.1.60:21").await?;
|
|
let _ = ftp_stream.login("Doe", "mumble").await?;
|
|
|
|
ftp_stream.mkdir("test_dir").await?;
|
|
ftp_stream.cwd("test_dir").await?;
|
|
assert!(ftp_stream.pwd().await?.ends_with("/test_dir"));
|
|
|
|
// store a file
|
|
let file_data = "test data\n";
|
|
let mut reader = Cursor::new(file_data.as_bytes());
|
|
ftp_stream.put("test_file.txt", &mut reader).await?;
|
|
|
|
// retrieve file
|
|
ftp_stream
|
|
.simple_retr("test_file.txt")
|
|
.await
|
|
.map(|bytes| assert_eq!(bytes.into_inner(), file_data.as_bytes()))?;
|
|
|
|
// remove file
|
|
ftp_stream.rm("test_file.txt").await?;
|
|
|
|
// cleanup: go up, remove folder, and quit
|
|
ftp_stream.cdup().await?;
|
|
|
|
ftp_stream.rmdir("test_dir").await?;
|
|
ftp_stream.quit().await?;
|
|
|
|
Ok(())
|
|
};
|
|
|
|
let result: Result<(), FtpError> = tokio::runtime::Builder::new_current_thread()
|
|
.enable_all()
|
|
.build()
|
|
.unwrap()
|
|
.block_on(future);
|
|
|
|
result.unwrap();
|
|
}
|