Skip to main content

ftp client/server for asyncio

Project description

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

ftp client/server for asyncio (http://aioftp.readthedocs.org)

Features

  • Simple.

  • Extensible.

  • Client socks proxy via siosocks (pip install aioftp[socks]).

Goals

  • Minimum usable core.

  • Do not use deprecated or overridden commands and features (if possible).

  • Very high level api.

Client use this commands: USER, PASS, ACCT, PWD, CWD, CDUP, MKD, RMD, MLSD, MLST, RNFR, RNTO, DELE, STOR, APPE, RETR, TYPE, PASV, ABOR, QUIT, REST, LIST (as fallback)

Server support this commands: USER, PASS, QUIT, PWD, CWD, CDUP, MKD, RMD, MLSD, LIST (but it’s not recommended to use it, cause it has no standard format), MLST, RNFR, RNTO, DELE, STOR, RETR, TYPE (“I” and “A”), PASV, ABOR, APPE, REST

This subsets are enough for 99% of tasks, but if you need something, then you can easily extend current set of commands.

Server benchmark

Compared with pyftpdlib and checked with its ftpbench script.

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

Dependencies

  • Python 3.7+

0.13.0 is the last version which supports python 3.5.3+

0.16.1 is the last version which supports python 3.6+

License

aioftp is offered under the Apache 2 license.

Library installation

pip install aioftp

Getting started

Client example

WARNING

For all commands, which use some sort of «stats» or «listing», aioftp tries at first MLSx-family commands (since they have structured, machine readable format for all platforms). But old/lazy/nasty servers do not implement this commands. In this case aioftp tries a LIST command, which have no standard format and can not be parsed in all cases. Take a look at FileZilla «directory listing» parser code. So, before creating new issue be sure this is not your case (you can check it with logs). Anyway, you can provide your own LIST parser routine (see the client documentation).

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())

Server example

import asyncio
import aioftp


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

asyncio.run(main())

Or just use simple server

python -m aioftp --help

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aioftp-0.21.4.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

aioftp-0.21.4-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

Details for the file aioftp-0.21.4.tar.gz.

File metadata

  • Download URL: aioftp-0.21.4.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for aioftp-0.21.4.tar.gz
Algorithm Hash digest
SHA256 28bb26d4616c7c381a1543281f987051b8d2d1d5bfaf023d9e7e2c2105c51bb9
MD5 a27556df39e8bfc41391e2b45e38f85f
BLAKE2b-256 ce24c6e36ad4e21a3913a5838d0192ac7afb6e3cf2711cf6cc878fddf82ddadc

See more details on using hashes here.

File details

Details for the file aioftp-0.21.4-py3-none-any.whl.

File metadata

  • Download URL: aioftp-0.21.4-py3-none-any.whl
  • Upload date:
  • Size: 37.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for aioftp-0.21.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ad7c1136754799808fca890ea41ea7ec8fcd1bb5167a1f46e04db15267242324
MD5 9cce93218d4166b9e905a7b816c7c2d3
BLAKE2b-256 90d3211850ff64f9035e27eeb8aaffc37ed66e12870949c5aee0f2414d704749

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page