Environment Construction:
- Python
- Windows/linux
- Pip Install pyftpdlib (install failed please download here: https://pypi.python.org/pypi/pyftpdlib/)
A line of code to fix things:
To the directory you intend to share, python-m pyftpdlib
Then we look at this, a simple FTP server has been completed, access to ftp://127.0.0.1:2121 (the default IP is 127.0.0.1, port is 2121)
In addition to the above, there are some optional parameters:
I specify an IP address (default is native IP address)
P Specify port (default is 2121)
W Write permission (default is read-only)
D Specify directory (default to current directory)
U Specify user name Login
P Set Login Password
If you want to build an FTP service on your LAN:
fromPyftpdlib.authorizersImportDummyauthorizer fromPyftpdlib.handlersImportFtphandler fromPyftpdlib.serversImportFtpserver#instantiate Dummyauthorizer to create an FTP userAuthorizer =Dummyauthorizer ()#Parameters: User name, password, directory, permissionsAuthorizer.add_user ('User','12345','e:\\', perm='ELRADFMWMT')#Anonymous Login#authorizer.add_anonymous ('/home/nobody ')Handler =Ftphandlerhandler.authorizer=Authorizer#parameters: IP, port, HandlerServer = Ftpserver (('0.0.0.0', +), handler)#set the IP address to 0.0.0.0 as the nativeServer.serve_forever ()
Read permissions:
"E" = Change directory (cwd,cdup command)
"L" = List file (list,nlst,stat,mlsd,mlst,size command)
"R" = Retrieving files from the server (RETR command)
Write permissions:
"A" = Append data to an existing file (AppE command)
"D" = delete file or directory (DELE,RMD command)
"F" = Rename file or directory (Rnfr,rnto command)
"M" = Create directory (MKD command)
"W" = Store file to server (Stor,stou command)
"M" = Change file Mode/permissions (SITE chmod command)
"T" = Change the file modification time (SITE mfmt command)
A python code to build an FTP service