giampaolo / pyftpdlib

Extremely fast and scalable Python FTP server library
MIT License
1.65k stars 265 forks source link

Unable to set custom home directory in `DummyAuthorizer().add_user()` #620

Closed milanmlft closed 5 months ago

milanmlft commented 5 months ago

Thanks for the wonderful package!

However, I ran into a ValueError: no such directory when trying to run the example from the DummyAuthorizer class:

from pyftpdlib.authorizers import DummyAuthorizer
authorizer = DummyAuthorizer()
authorizer.add_user('user', 'password', '/home/user', perm='elradfmwMT')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[6], line 1
----> 1 authorizer.add_user('user', 'password', '/home/user', perm='elradfmwMT')

File ~/.pyenv/versions/3.10.13/envs/pixl-3.10.13/lib/python3.10/site-packages/pyftpdlib/authorizers.py:106, in DummyAuthorizer.add_user(self, username, password, homedir, perm, msg_login, msg_quit)
    104     homedir = homedir.decode('utf8')
    105 if not os.path.isdir(homedir):
--> 106     raise ValueError('no such directory: %r' % homedir)
    107 homedir = os.path.realpath(homedir)
    108 self._check_permissions(username, perm)

ValueError: no such directory: '/home/user'

Any idea what maybe causing this? Thanks!

giampaolo commented 5 months ago

The error message says it all no such directory: '/home/user'. :D That's just an example from the doc. You should use a path of a directory which exists.

milanmlft commented 5 months ago

Thanks for the reply @giampaolo! Might be worth adding a note to the docs then to specify that :) and maybe some example code of how to create that directory? At the moment I can only get it to work if I use "." as home directory. I'm probably missing something obvious, but it would be great if the documentation could help out a bit more. Thanks!