Skip to main content

用于异步的 ftp 客户端/服务器

项目描述

主分支的 Github 操作 ci 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 ( pip install aioftp[socks] ) 的客户端 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

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.7+

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

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

执照

aioftp 在 Apache 2 许可下提供。

库安装

pip install aioftp

入门

客户端示例

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.21.3.tar.gz (51.8 kB 查看哈希

已上传 source

内置分布

aioftp-0.21.3-py3-none-any.whl (37.1 kB 查看哈希

已上传 py3