16个版本 (8个稳定版)

使用旧的Rust 2015

3.0.1 2018年4月15日
3.0.0 2018年2月28日
2.2.1 2017年3月2日
2.1.2 2017年9月30日
0.0.2 2014年11月28日

#164 in #安全

Download history 960/week @ 2024-03-14 1230/week @ 2024-03-21 1626/week @ 2024-03-28 1012/week @ 2024-04-04 1168/week @ 2024-04-11 920/week @ 2024-04-18 866/week @ 2024-04-25 907/week @ 2024-05-02 930/week @ 2024-05-09 801/week @ 2024-05-16 961/week @ 2024-05-23 1268/week @ 2024-05-30 1104/week @ 2024-06-06 1296/week @ 2024-06-13 861/week @ 2024-06-20 888/week @ 2024-06-27

4,562 每月下载量
用于 21 个crate(13个直接使用)

Apache-2.0/MIT

37KB
525

rust-ftp

Rust的FTP客户端

Number of Crate Downloads Crate Version Crate License Build Status Coverage Status

文档

安装

默认情况下禁用了FTPS支持。要启用它,应在Cargo.toml中激活secure

[dependencies]
ftp = { version = "<version>", features = ["secure"] }

用法

extern crate ftp;

use std::str;
use std::io::Cursor;
use ftp::FtpStream;

fn main() {
    // Create a connection to an FTP server and authenticate to it.
    let mut ftp_stream = FtpStream::connect("127.0.0.1:21").unwrap();
    let _ = ftp_stream.login("username", "password").unwrap();

    // Get the current directory that the client will be reading from and writing to.
    println!("Current directory: {}", ftp_stream.pwd().unwrap());
    
    // Change into a new directory, relative to the one we are currently in.
    let _ = ftp_stream.cwd("test_data").unwrap();

    // Retrieve (GET) a file from the FTP server in the current working directory.
    let remote_file = ftp_stream.simple_retr("ftpext-charter.txt").unwrap();
    println!("Read file with contents\n{}\n", str::from_utf8(&remote_file.into_inner()).unwrap());

    // 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);
    println!("Successfully wrote greeting.txt");

    // Terminate the connection to the server.
    let _ = ftp_stream.quit();
}

许可

许可方式任选其一

任选。

贡献

除非您明确表示,否则根据Apache-2.0许可中定义的,您有意提交的任何贡献,都应如上双重许可,不附加任何额外条款或条件。

开发环境

您只需要Rust和Docker来开发和运行rust-ftp的测试。tests文件夹包含一个Dockerfile,用于安装和配置vsftpd服务器。

创建Docker镜像

docker build -t ftp-server tests

启动用于测试的FTP服务器

tests/ftp-server.sh

此脚本以分离模式运行ftp-server镜像,并启动vsftpd守护程序。它绑定了21(FTP)端口以及65000-65010范围的被动连接端口。

一旦运行实例,要运行测试,请输入

cargo test

以下命令可能有用

# List running containers of ftp-server image
# (to include stopped containers use -a option)
docker ps --filter ancestor=ftp-server

# To stop and remove a container
docker stop container_name
docker rm container_name

# To remove the image
docker rmi ftp-server

依赖关系

~6.5MB
~119K SLoC