pyftpdlib.authorizers里面有3个authorizer,我一般就用DummyAuthorizer,因为创建的用户与底层系统无关。如果想有关也是可以的,用UnixAuthorizer,或者WindowsAuthorizer。
pyftpdlib在创建用户的时候,用大小写字母来表示具体的权限:
Read permissions:
"e" = change directory (CWD, CDUP commands)
"l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE commands)
"r" = retrieve file from the server (RETR command)
Write permissions:
"a" = append data to an existing file (APPE command)
"d" = delete file or directory (DELE, RMD commands)
"f" = rename file or directory (RNFR, RNTO commands)
"m" = create directory (MKD command)
"w" = store a file to the server (STOR, STOU commands)
"M" = change file mode / permission (SITE CHMOD command) New in 0.7.0
"T" = change file modification time (SITE MFMT command) New in 1.5.3
所以在使用pyftpdlib时,常常看到这样的代码:
>>> from pyftpdlib.authorizers import DummyAuthorizer
>>> authorizer = DummyAuthorizer()
>>> authorizer.add_user('user', 'password', '/home/user', perm='elradfmwMT')
>>> authorizer.add_anonymous('/home/nobody')
authorizer.add_user函数中的perm就是权限控制,而add_anonymous函数,默认使用了readonly权限。
add_user函数给用户设置了一个home directory路径,如果在这个路径下,需要对不同文件夹给出不同的权限,这个时候就要用override_perm函数,做更加精细的控制。
-- EOF --