6

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.

Nilesh Agrawal
  • 3,002
  • 10
  • 26
  • 54
Nilesh Nar
  • 169
  • 3
  • 3
  • 9

3 Answers3

4

I can recommend pyftpdlib hosted at Github

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).
elPastor
  • 8,435
  • 11
  • 53
  • 81
moi
  • 1,835
  • 2
  • 18
  • 25
2

Check out the FTP examples with twisted

Also a simple implementation: ftpdrop.py

pyfunc
  • 65,343
  • 15
  • 148
  • 136
  • Thanks again...The whole day i was doing google for FTP sample code,but i wasn't successful.... U made my work simpler...Thanks a lot... – Nilesh Nar Oct 23 '10 at 20:03
0

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

Francesco De Vittori
  • 9,100
  • 6
  • 33
  • 43