pub struct FtpClient { /* private fields */ }Expand description
FTP 客户端
异步 FTP 协议实现,支持:
- 被动模式优先,主动模式 fallback
- 二进制/ASCII 传输模式切换
- 断点续传(REST 命令)
- 目录列表解析(Unix/Windows 格式)
§示例
use aria2_core::ftp::connection::{FtpClient, FtpMode};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = FtpClient::connect("ftp.example.com", 21, FtpMode::Passive).await?;
client.login("anonymous", "user@example.com").await?;
client.set_binary_mode(true).await?;
let files = client.list_directory("/").await?;
for file in &files {
println!("{} {} {}", if file.is_dir { "D" } else { "F" }, file.size, file.name);
}
client.quit().await?;
Ok(())
}Implementations§
Source§impl FtpClient
impl FtpClient
Sourcepub async fn set_binary_mode(&mut self, enabled: bool) -> Result<()>
pub async fn set_binary_mode(&mut self, enabled: bool) -> Result<()>
Sourcepub async fn passive_mode(&mut self) -> Result<TcpStream>
pub async fn passive_mode(&mut self) -> Result<TcpStream>
Sourcepub async fn active_mode(&mut self) -> Result<TcpStream>
pub async fn active_mode(&mut self) -> Result<TcpStream>
Sourcepub async fn list_directory(&mut self, path: &str) -> Result<Vec<FtpFileInfo>>
pub async fn list_directory(&mut self, path: &str) -> Result<Vec<FtpFileInfo>>
Sourcepub async fn download_file(
&mut self,
remote_path: &str,
offset: Option<u64>,
) -> Result<TcpStream>
pub async fn download_file( &mut self, remote_path: &str, offset: Option<u64>, ) -> Result<TcpStream>
Auto Trait Implementations§
impl !Freeze for FtpClient
impl RefUnwindSafe for FtpClient
impl Send for FtpClient
impl Sync for FtpClient
impl Unpin for FtpClient
impl UnsafeUnpin for FtpClient
impl UnwindSafe for FtpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more