1. Thomas Weholt
  2. djftpd


Django Authenticating FTP Server

Version : 0.2.0 Author : Thomas Weholt <thomas@weholt.org> License : GPL v3.0 Status : Beta Url : http://bitbucket.org/weholt/djftpd/


Djftpd is a ftpserver based on pyftpdlib using the user management in django for authentication. Handy for giving easy access ftp-accounts to let users upload static content etc.


python setup.py install

Required in settings.py:

  1. Add djftpd to your installed apps.

Optional in settings.py:

  1. get_ftp_home_dir: A method which takes an username as parameter and returns a complete folder to use as homefolder for the given user.
  2. FTP_PORT : If you want to use another port than 21.
  3. FTP_ADDRESS : If you want to use a specific address, defaults to ''.
  4. read_perms/write_perms: By default the user has full access the directory returned by the get_ftp_home_dir, but you can override the read/write-permissions by setting custom permissions. For more information about this read the pyftpdlib source and look for read_perms and write_perms.
  5. ftp_handler: You can also specify a custom ftp_handler to process actions like user_login, user_logout, downloads and uploads etc, for logging purposes for instance. Read more about how to create your own handler here http://code.google.com/p/pyftpdlib/wiki/Tutorial#3.8_-_Event_callbacks
  6. FTP_WELCOME_MSG: the welcome message to display when users log on.


Djftpd comes with a django management command called startftpserver. It will start the ftp server in blocking mode. If you want to use it in a stand-alone script, perhaps daemonize/fork it, on linux do something (untested code follows) like:

import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' # points to your settings.py file

from djftpd import create_django_ftpserver

## {{{ http://code.activestate.com/recipes/66012/ (r1)
def do_fork(method_to_deamonize):
    # do the UNIX double-fork magic, see Stevens' "Advanced
    # Programming in the UNIX Environment" for details (ISBN 0201563177)
        pid = os.fork()
        if pid > 0:
            # exit first parent
    except OSError, e:
        print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)

    # decouple from parent environment

    # do second fork
        pid = os.fork()
        if pid > 0:
            # exit from second parent, print eventual PID before
            print "Daemon PID %d" % pid
    except OSError, e:
        print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)

    # start the daemon main loop
    ## end of http://code.activestate.com/recipes/66012/ }}}

def start_server():
    ftpd = create_django_ftpserver()



  • pyftpdlib
  • django