0

I am trying to use pyftpdlib for serving files via ftp. I was able to run a sample server but I am looking for a way to change working directory for a user right after he is logged in.

Current situation is that after log in user PWD always return '/' (the root):

ftp> pwd
257 "/" is the current directory. 

I want after user is logged in server to automatically change its directory to let say 'test' so PWD after login to return:

ftp> pwd
257 "/test" is the current directory. 

I looked in the documentation and see that there is on_login() handler but no examples how to use it.

Any ideas will be helpfull

I am adding sample code:

import os

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', '12345', homedir='c:\\temp', perm='elradfmwMT')
    handler = FTPHandler
    handler.authorizer = authorizer
    address = ('', 21)
    server = FTPServer(address, handler)
    server.serve_forever()

if __name__ == '__main__':
    main()

I have also folder c:\temp\test that I want to switch to automatically without setting it as a root. Root should remain c:\temp

TestMechanic
  • 163
  • 1
  • 1
  • 11

1 Answers1

0

Just change the homedir parameter to your desired path:

def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('user', 'pwd', homedir='/test', perm='elradfmwMT') 
    handler.authorizer = authorizer
    server = FTPServer(('', 2121))
    server.serve_forever()

if __name__ == "__main__":
    main()

Reference: https://pyftpdlib.readthedocs.io/en/latest/api.html

Cristofor
  • 2,077
  • 2
  • 15
  • 23