Simple FTP Server Solution With Python

I spent the last few days dealing with setting up an ftp server on by ubuntu vps and haven't figured out a solution. Then I tried asking my friends thru my facebook account. My friend Sakti came up with a very simple and elegant solution using python.

The solution uses pyftpdlib package. To install the package is really simple:
$ easy_install pyftpdlib
or
$ pip install pyftpdlib
after that create the folowing script and save it as a python file:
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
authorizer = DummyAuthorizer()
authorizer.add_user("user", "password", "/home/user", perm="elradfmw")
authorizer.add_anonymous("/home/nobody")
handler = FTPHandler
handler.authorizer = authorizer
server = FTPServer(("0.0.0.0", 21), handler)
server.serve_forever()
Then run the script and try accessing your server using ftp.



Only 10 lines but it works like a charm, a very python way :)

If you want to download the script you can get it here.
Hope that helps.
regards
-E-
follow @femmerling on twitter

Comments

  1. I guess there's a typo in last line. It should be "server.serve_forever()", judging by pyftplib's documentation.

    ReplyDelete
  2. I think it:
    authorizer = DummyAuthorizer
    should be
    authorizer = DummyAuthorizer()

    ReplyDelete

Post a Comment

Popular posts from this blog

Customizing Sanic's Logging output on Gunicorn

5 Takeaways From My Past 5 Years With Coral, Prism, Midtrans and Gojek

Lessons From Leading and Developing Product Engineering Teams - Part 1