跳转到主要内容

基于asyncio的ftp客户端/服务器

项目描述

Github actions ci for master branch https://codecov.io/gh/aio-libs/aioftp/branch/master/graph/badge.svg https://img.shields.io/pypi/v/aioftp.svg https://img.shields.io/pypi/pyversions/aioftp.svg https://pepy.tech/badge/aioftp/month

基于asyncio的ftp客户端/服务器 (http://aioftp.readthedocs.org)

功能

  • 简单。

  • 可扩展。

  • 通过 siosocks 使用客户端socks代理 (pip install aioftp[socks])。

目标

  • 最小可用的核心。

  • 不使用已弃用或覆盖的命令和功能(如果可能)。

  • 非常高级的API。

客户端使用以下命令:USER、PASS、ACCT、PWD、CWD、CDUP、MKD、RMD、MLSD、MLST、RNFR、RNTO、DELE、STOR、APPE、RETR、TYPE、PASV、ABOR、QUIT、REST、LIST(作为后备)

服务器支持以下命令:USER、PASS、QUIT、PWD、CWD、CDUP、MKD、RMD、MLSD、LIST(但建议不要使用它,因为它没有标准格式),MLST、RNFR、RNTO、DELE、STOR、RETR、TYPE(“I”和“A”)、PASV、ABOR、APPE、REST

这些子集足以完成99%的任务,但如果需要,可以轻松扩展当前命令集。

服务器基准测试

pyftpdlib和其ftpbench脚本的测试结果进行比较。

aioftp 0.8.0

STOR (client -> server)                              284.95 MB/sec
RETR (server -> client)                              408.44 MB/sec
200 concurrent clients (connect, login)                0.18 secs
STOR (1 file with 200 idle clients)                  287.52 MB/sec
RETR (1 file with 200 idle clients)                  382.05 MB/sec
200 concurrent clients (RETR 10.0M file)              13.33 secs
200 concurrent clients (STOR 10.0M file)              12.56 secs
200 concurrent clients (QUIT)                          0.03 secs

aioftp 0.21.4(Python 3.11.2)

STOR (client -> server)                              280.17 MB/sec
RETR (server -> client)                              399.23 MB/sec
200 concurrent clients (connect, login)                0.22 secs
STOR (1 file with 200 idle clients)                  248.46 MB/sec
RETR (1 file with 200 idle clients)                  362.43 MB/sec
200 concurrent clients (RETR 10.0M file)               5.41 secs
200 concurrent clients (STOR 10.0M file)               2.04 secs
200 concurrent clients (QUIT)                          0.04 secs

pyftpdlib 1.5.2

STOR (client -> server)                             1235.56 MB/sec
RETR (server -> client)                             3960.21 MB/sec
200 concurrent clients (connect, login)                0.06 secs
STOR (1 file with 200 idle clients)                 1208.58 MB/sec
RETR (1 file with 200 idle clients)                 3496.03 MB/sec
200 concurrent clients (RETR 10.0M file)               0.55 secs
200 concurrent clients (STOR 10.0M file)               1.46 secs
200 concurrent clients (QUIT)                          0.02 secs

依赖项

  • Python 3.8+

0.13.0是支持Python 3.5.3+的最后一个版本

0.16.1是支持Python 3.6+的最后一个版本

0.21.4是支持Python 3.7+的最后一个版本

许可证

aioftp是在Apache 2许可证下提供的。

库安装

pip install aioftp

入门指南

客户端示例

警告

对于所有使用某种“统计”或“列出”的命令,aioftp首先尝试MLSx-家族命令(因为它们对所有平台都有结构化、机器可读的格式)。但旧的/懒惰/恶劣的服务器没有实现这些命令。在这种情况下,aioftp将尝试一个LIST命令,它没有标准格式,并且在所有情况下都不能被解析。请参阅FileZilla的“目录列出”解析器代码。所以,在创建新问题之前,请确保这不是你的情况(你可以通过日志来检查)。无论如何,你可以提供自己的LIST解析程序(请参阅客户端文档)。

import asyncio
import aioftp


async def get_mp3(host, port, login, password):
    async with aioftp.Client.context(host, port, login, password) as client:
        for path, info in (await client.list(recursive=True)):
            if info["type"] == "file" and path.suffix == ".mp3":
                await client.download(path)


async def main():
    tasks = [
        asyncio.create_task(get_mp3("server1.com", 21, "login", "password")),
        asyncio.create_task(get_mp3("server2.com", 21, "login", "password")),
        asyncio.create_task(get_mp3("server3.com", 21, "login", "password")),
    ]
    await asyncio.wait(tasks)

asyncio.run(main())

服务器示例

import asyncio
import aioftp


async def main():
    server = aioftp.Server([user], path_io_factory=path_io_factory)
    await server.run()

asyncio.run(main())

或者直接使用简单服务器

python -m aioftp --help

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

aioftp-0.22.3.tar.gz (62.2 kB 查看哈希值

上传时间

构建分发

aioftp-0.22.3-py3-none-any.whl (37.8 kB 查看哈希值

上传于 Python 3

支持者