1 Star 0 Fork 0

mamh-mixed/pyftpdlib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Quick links

About

Python FTP server library provides a high-level portable interface to easily write very efficient, scalable and asynchronous FTP servers with Python. It is the most complete RFC-959 FTP server implementation available for Python programming language.

Features

  • Extremely lightweight, fast and scalable (see why and benchmarks).
  • Uses sendfile(2) (see pysendfile) system call for uploads.
  • Uses epoll() / kqueue() / select() to handle concurrency asynchronously.
  • ...But can optionally skip to a multiple thread / process model (as in: you'll be free to block or use slow filesystems).
  • Portable: entirely written in pure Python.
  • Supports FTPS (RFC-4217), IPv6 (RFC-2428), Unicode file names (RFC-2640), MLSD/MLST commands (RFC-3659).
  • Support for virtual users and virtual filesystem.
  • Flexible system of "authorizers" able to manage both "virtual" and "real" users on on both UNIX and Windows.

Performances

Despite being written in an interpreted language, pyftpdlib has transfer rates comparable or superior to common UNIX FTP servers written in C. It usually tends to scale better (see benchmarks) because whereas vsftpd and proftpd use multiple processes to achieve concurrency, pyftpdlib only uses one (see the C10K problem).

pyftpdlib vs. proftpd 1.3.4

benchmark type pyftpdlib proftpd speedup
STOR (client -> server) 585.90 MB/sec 600.49 MB/sec -0.02x
RETR (server -> client) 1652.72 MB/sec 1524.05 MB/sec +0.08
300 concurrent clients (connect, login) 0.19 secs 9.98 secs +51x
STOR (1 file with 300 idle clients) 585.59 MB/sec 518.55 MB/sec +0.1x
RETR (1 file with 300 idle clients) 1497.58 MB/sec 1478.19 MB/sec 0x
300 concurrent clients (RETR 10M file) 3.41 secs 3.60 secs +0.05x
300 concurrent clients (STOR 10M file) 8.60 secs 11.56 secs +0.3x
300 concurrent clients (QUIT) 0.03 secs 0.39 secs +12x

pyftpdlib vs. vsftpd 2.3.5

benchmark type pyftpdlib vsftpd speedup
STOR (client -> server) 585.90 MB/sec 611.73 MB/sec -0.04x
RETR (server -> client) 1652.72 MB/sec 1512.92 MB/sec +0.09
300 concurrent clients (connect, login) 0.19 secs 20.39 secs +106x
STOR (1 file with 300 idle clients) 585.59 MB/sec 610.23 MB/sec -0.04x
RETR (1 file with 300 idle clients) 1497.58 MB/sec 1493.01 MB/sec 0x
300 concurrent clients (RETR 10M file) 3.41 secs 3.67 secs +0.07x
300 concurrent clients (STOR 10M file) 8.60 secs 9.82 secs +0.07x
300 concurrent clients (QUIT) 0.03 secs 0.01 secs +0.14x

For more benchmarks see here.

Command line usage

Start a FTP server, with an anonymous user with write permissions, on port 2121:

$ python3 -m pyftpdlib --write
RuntimeWarning: write permissions assigned to anonymous user.
  self._check_permissions(username, perm)
[I 2024-06-23 13:49:35] concurrency model: async
[I 2024-06-23 13:49:35] masquerade (NAT) address: None
[I 2024-06-23 13:49:35] passive ports: None
[I 2024-06-23 13:49:35] >>> starting FTP server on 0.0.0.0:2121, pid=763634 <<<

API usage

>>> from pyftpdlib.authorizers import DummyAuthorizer
>>> from pyftpdlib.handlers import FTPHandler
>>> from pyftpdlib.servers import FTPServer
>>>
>>> authorizer = DummyAuthorizer()
>>> authorizer.add_user("user", "12345", "/home/giampaolo", perm="elradfmwMT")
>>> authorizer.add_anonymous("/home/nobody")
>>>
>>> handler = FTPHandler
>>> handler.authorizer = authorizer
>>>
>>> server = FTPServer(("127.0.0.1", 21), handler)
>>> server.serve_forever()
[I 13-02-19 10:55:42] >>> starting FTP server on 127.0.0.1:21 <<<
[I 13-02-19 10:55:42] poller: <class 'pyftpdlib.ioloop.Epoll'>
[I 13-02-19 10:55:42] masquerade (NAT) address: None
[I 13-02-19 10:55:42] passive ports: None
[I 13-02-19 10:55:42] use sendfile(2): True
[I 13-02-19 10:55:45] 127.0.0.1:34178-[] FTP session opened (connect)
[I 13-02-19 10:55:48] 127.0.0.1:34178-[user] USER 'user' logged in.
[I 13-02-19 10:56:27] 127.0.0.1:34179-[user] RETR /home/giampaolo/.vimrc completed=1 bytes=1700 seconds=0.001
[I 13-02-19 10:56:39] 127.0.0.1:34179-[user] FTP session closed (disconnect).

other code samples

Donate

A lot of time and effort went into making pyftpdlib as it is right now. If you feel pyftpdlib is useful to you or your business and want to support its future development please consider donating me some money.

MIT License Copyright (c) 2007 Giampaolo Rodola' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

https://github.com/mamh-mixed/pyftpdlib 展开 收起
Python 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mamh-mixed/pyftpdlib.git
git@gitee.com:mamh-mixed/pyftpdlib.git
mamh-mixed
pyftpdlib
pyftpdlib
master

搜索帮助