FTP server (File Transfer Protocol Server) is a computer that provides file storage and access services on the Internet. They Services are provided in accordance with the FTP protocol. FTP is File Transfer Protocol. As the name suggests, it is a protocol specifically used to transfer files. Simply put, a server that supports the FTP protocol is an FTP server.
Summary:
This article mainly explains the use of PHP's swoole extension to implement the ftp server, and at the same time expand the personalized functions and security of the ftp server. Really realize an ftp server that you have complete control over, an ftp server that can be customized.
Text:
Everyone must be familiar with FTP servers, and there are many ready-made software to use them. However, the functions of free software sometimes do not meet your needs, and secondary development is not possible, and the price of paid software is relatively high. PHP's swoole extension is a high-performance network communication framework for PHP language. It provides asynchronous multi-threaded server of PHP language, asynchronous TCP/UDP network client, asynchronous MySQL, database connection pool, AsyncTask, message queue, millisecond timer, asynchronous File reading and writing, asynchronous DNS query.
Swoole can be widely used in the Internet, mobile communications, enterprise software, online games, Internet of Things, Internet of Vehicles, smart homes and other fields. Using PHP Swoole as a network communication framework can greatly improve the efficiency of enterprise IT R&D teams and focus more on developing innovative products.
Swoole has a built-in asynchronous non-blocking, multi-threaded network IO server at the bottom layer. PHP programmers only need to handle event callbacks and do not need to care about the underlying layer. Unlike fully asynchronous frameworks such as Nginx/Tornado/Node.js, Swoole supports both fully asynchronous and synchronous.
With this foundation, server development based on TCP/IP protocol becomes easy. You may ask, C# and other languages can also implement it, why use PHP? I think the main consideration is development efficiency. PHP is a scripting language that does not require compilation and is fast in development and deployment.
No need to elaborate, here are the steps:
00 Prepare the platform, I am using CentOS7 here;
01 To install php and swoole extensions, please refer to http://wiki.swoole.com/wiki/page/6.html;
02 Set the character set. Since file names processed by ftp are prone to garbled characters, it is recommended to set the character set of the operating system to GB18030, which is consistent with Windows. Although most ftp clients currently also support utf8 file name encoding, however, It's less than satisfying to use. Please feel free to tell me any good solutions, thank you very much;
03 Start writing php programs and test php programs;
04 Deploy the php version of ftp server.
The functional goals of this article to achieve the ftp server are:
* User and group management;
* Self-service password modification and reset;
* Folder permission management;
* IP access control;
* Viewed by online users;
* View disk space usage;
* SSL support to protect password and file transmission security;
* Built-in web management page to facilitate remote management.
Project directory:
FtpServer
|
-conf
|
|
|
-config.php //FTP configuration file
|
-ssl.crt //ssl certificate
|
-ssl.key //ssl key
|
-inc
|
|
|
-CSmtp.php //Smtp email class, used for FTP password sending and reset
|
-ShareMemory.php //Shared memory operation class
|
-User.php //User management, file permission management, IP access control
|
-logs //Log file
|
-reference //Reference document
|
-web
|
|
|
-wwwroot //FTP Web management website
|
-CWebServer.php //FTP built-in http server
|
-CFtpServer.php //FTP server main program
-MyFtpServer.php //FTP entry program
This article will introduce it to you here first, and will continue to be updated in the future.