DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Setup Lightweight Python FTP Server for Test


Based on Python FTP server library (pyftpdlib)

Install

  1. Start a virtual environment;

  2. $ easy_install pyftpdlib (the version number is 1.3.0)

or download pyftpdlib-1.3.0.tar.gz manually and "python setup.py install".

Usage

Run the following script to startup server:

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
authorizer = DummyAuthorizer()
authorizer.add_user("user", "12345", "/home/chad/tmp", perm="elradfmw")
authorizer.add_anonymous("/home/chad/tmp2")
# you have a named and an anonymous user to login
handler = FTPHandler
handler.authorizer = authorizer
server = FTPServer(("0.0.0.0", 2121), handler)
server.serve_forever()

If you set the port to "21", a "permission denied" error raises. So I changed it to 2121. If you only accept local connection, modify server ip as "127.0.0.1" instead of "0.0.0.0".

Use this server in command line:

ftp 10.21.2.7 2121
// user name and password
pwd
ls
get file1.txt
put file2.txt

And a groovy ftp client:

import org.apache.commons.net.ftp.FTPClient
println("About to connect....");
new FTPClient().with {
    connect "localhost", 2121
    login "user", "123"
    def names = listNames("/")
    print names
    logout()
    disconnect()
}
println("Done.");

Run this client:

groovy -cp .../commons-net-3.1.jar ftpclient.groovy

On my machine this path is: ~/.m2/repository/commons-net/commons-net/3.1/commons-net-3.1.jar



Published

Jan 24, 2014

Last Updated

Jan 24, 2014

Category

Tech

Tags

  • FTP 7
  • Python 136
  • server 10

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor