python中FTP服务器的简单代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4005507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 13:49:00  来源:igfitidea点击:

Simple code for FTP Server in python

pythonftp-server

提问by Nilesh Nar

I want to built a simple FTP server in python which will serve the client in just downloading a text file. Can any one kindly help me by suggesting the best study material to refer and help me finding some code snippets.

我想在 python 中构建一个简单的 FTP 服务器,它只需下载一个文本文件就可以为客户端提供服务。任何人都可以通过建议最好的学习材料来帮助我参考并帮助我找到一些代码片段。

采纳答案by pyfunc

Check out the FTP examples with twisted

查看带有扭曲的 FTP 示例

Also a simple implementation: ftpdrop.py

也是一个简单的实现:ftpdrop.py

回答by Francesco De Vittori

Thisis probably the best you can find to understand the FTP protocol. Implementation should be pretty simple once you've understood the mechanism.

可能是您能找到的最好的了解 FTP 协议的方法。一旦您了解了机制,实现应该非常简单。

回答by moi

I can recommend pyftpdlib hosted at Google Code

我可以推荐托管在 Google Code 上的 pyftpdlib

Example:

例子:

    >>> 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="elradfmw")
>>> 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).