One line of Python code is used to quickly implement the FTP server and pythonftp
Abstract: This is especially useful when you want to quickly share a directory. You only need one line of code to implement it.
This is especially useful when you want to quickly share a directory. You only need one line of code.
Before that, I used Linux's vsftpd software package to build an FTP server. Now I found that pyftpdlib can be used to implement FTP server functions in a simpler way.
Environment requirements
- Python 1, 2.7
- Windows/Linux
Environment Construction
One line of code implements FTP Server
The-m option of Python is used as a simple independent server. This is especially useful when you want to quickly share a directory.
Execute the following command under the directory to be shared to share the current directory (anonymous login)
Now a simple FTP server has been set up. You can access ftp: // 127.0.0.1: 2121.
(The default IP address is 127.0.0.1 and the port is 2121)
Optional Parameter
- -I: Specifies the IP address (the local IP Address by default)
- -P specifies the port (default value: 2121)
- -W write permission (read-only by default)
- -D specifies the directory (the default is the current directory)
- -U specifies the user name to log on
- -P: Set the logon password.
Simple Example
The preceding command line can be used to implement a simple FTP server. However, to build a powerful and complete FTP service, many configurations are involved. You need to use the APIS provided by Pyftpdlib to compile it. The following is a simple example.
Perm permission options
Read Permission:
- "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 Permission:
- "A" = append data to an existing file (APPE Command)
- "D" = delete a file or directory (DELE, RMD Command)
- "F" = rename a file or directory (RNFR, RNTO command)
- "M" = create a directory (MKD Command)
- "W" = store the file to the server (STOR, STOU command)
- "M" = change file mode/permission (site chmod command)
- "T" = change the file modification time (site mfmt command)
Reference
Pyftpdlib document: http://pyftpdlib.readthedocs.io/en/latest/index.html
Summary
The above is a small series of Python code introduced to you to quickly implement the FTP server, I hope to help you, if you have any questions, please leave a message, the small series will reply to you in a timely manner. Thank you very much for your support for the help House website!