python中的一行ftp服务器

2024-03-29 14:40:43 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
3条回答

必需的Twisted示例:

twistd -n ftp

可能有用:

twistd ftp --help

Usage: twistd [options] ftp [options].
WARNING: This FTP server is probably INSECURE do not use it.
Options:
  -p, --port=           set the port number [default: 2121]
  -r, --root=           define the root of the ftp-site. [default:
                    /usr/local/ftp]
  --userAnonymous=  Name of the anonymous user. [default: anonymous]
  --password-file=  username:password-style credentials database
  --version         
  --help            Display this help and exit.

从Giampaolo Rodola签出pyftpdlib。它是python最好的ftp服务器之一。它被用于谷歌的chromium(他们的浏览器)和bazaar(一个版本控制系统)。它是Python上最完整的RFC-959(又称FTP服务器实现规范)实现。

从命令行:

python -m pyftpdlib

或者“我的服务器.py”:

#!/usr/bin/env python

from pyftpdlib import servers
from pyftpdlib.handlers import FTPHandler
address = ("0.0.0.0", 21)  # listen on every IP on my machine on port 21
server = servers.FTPServer(address, FTPHandler)
server.serve_forever()

如果你想要更复杂的东西,网站上有更多的例子。

要获取命令行选项列表,请执行以下操作:

python -m pyftpdlib --help

注意,如果要覆盖或使用标准ftp端口,则需要管理员权限(例如sudo)。

为什么不使用单行HTTP服务器呢?

python -m SimpleHTTPServer 8000

将通过端口8000上的HTTP提供当前工作目录的内容。

如果使用Python 3,则应该编写

python3 -m http.server 8000

参见2.x的SimpleHTTPServer模块文档和3.x的http.server文档

顺便说一下,在这两种情况下port参数都是可选的。

相关问题 更多 >