Environment build:
- python
- windows/linux
- pip install pyftpdlib (if the installation fails, please download it here: https://pypi.python.org/pypi/pyftpdlib/ )
One line of code to do:
Execute in the directory you intend to share, python -m pyftpdlib
Then let's take a look. So far, a simple FTP server has been built, just visit ftp://127.0.0.1:2121 (the default IP is 127.0.0.1 and the port is 2121)
In addition to the above, there are some optional parameters:
-
i Specify the IP address (default is the IP address of the machine)
-
p specifies the port (default is 2121)
-
w write permission (default is read only)
-
d specifies the directory (defaults to the current directory)
-
u Specify the user name to log in
-
P Set the login password
If you want to build an FTP service in the LAN:
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer #Instantiate
DummyAuthorizer to create ftp user
authorizer = DummyAuthorizer() #Parameters
: username, password, directory, permissions
authorizer.add_user( ' user ' , ' 12345 ' , ' E:\\ ' , perm= ' elradfmwMT ' )
#anonymous login # authorizer.add_anonymous
( '/home/nobody')
handler =FTPHandler
handler.authorizer = authorizer
#Parameters : IP, port, handler
server = FTPServer(( ' 0.0.0.0 ' , 21), handler) #Set to 0.0.0.0 as the local IP address
server.serve_forever()
Read permission:
-
"e" = change directory (CWD, CDUP commands)
-
"l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE commands)
-
"r" = retrieve file from server (RETR command)
Write permission:
-
"a" = append data to existing file (APPE command)
-
"d" = delete file or directory (DELE, RMD command)
-
"f" = rename file or directory (RNFR, RNTO commands)
-
"m" = create directory (MKD command)
-
"w" = store file to server (STOR, STOU commands)
-
"M" = change file mode/permissions (SITE CHMOD command)
-
"T" = change file modification time (SITE MFMT command)