This article mainly covers tips for vsftp speed limiting. Within the configuration file, other common configuration policy techniques are described, such as anonymous user restrictions, log printing, directory restrictions, user type restrictions, and server IP restrictions. Please check the code in the file below for details.
As an FTP server, when many users (CPs) are uploading files simultaneously, it is necessary to limit FTP user speeds given a certain amount of server bandwidth. A detailed explanation follows below.
First, if those are all local users, the speed limiting method is:
Add the following line to /etc/vsftpd/vsftpd.conf: user_config_dir=/etc/vsftpd/userconf.
Second, create the directory /etc/vsftpd/userconf/, and then inside this directory create a file named after the user whose speed you want to limit. The filename should be the username, for example, yangkai. Add a line like “local_max_rate=400000” inside this file, and yangkai’s maximum upload and download speed will be limited to 400k. You can also set permissions here, such as adding “write_enable=no” to set read-only permissions.
Third, to limit all local users: add local_max_rate=400000 to /etc/vsftpd/vsftpd.conf to restrict all local users. To limit the speed of anonymous users, add anon_max_rate=400000.
Question: Why didn’t I use the method introduced in the third point for speed limiting?
Explanation: Some time ago, I read an article reviewing the railway ministry’s ticket booking website. It mentioned that “business requirements determine system architecture; analysis and commentary detached from requirements are meaningless.” That is roughly the gist—I don’t recall the exact wording. Our data flow is: CP upload > Platform processing > Publish to Huawei streaming media server. The transmission between our platform and the streaming media server is internal, also via FTP. If we used that method for speed limiting, it would impact the business, and the client would think we are pretty clueless. Or, someone might suggest using other methods for data transfer with the streaming media server, such as HTTP. Methods certainly exist, but you’d need both sides to modify their programs. That’s obviously unrealistic, because I don’t have that much authority!
Summary: The solution that meets the client’s needs is the best solution. A fancy solution does not necessarily earn you recognition. Even when building a product, you must first clearly understand market demand, then design the product, and finally promote it.
Appendix: vsftp.conf configuration file
- anonymous_enable=NO
- local_enable=YES
- write_enable=YES
- download_enable=YES
- local_umask=022
- dirmessage_enable=YES
- xferlog_enable=YES
- connect_from_port_20=YES
- chroot_list_enable=YES
- chroot_list_file=/etc/vsftpd.chroot_list
- chroot_local_user=YES
- listen=YES
- pam_service_name=vsftpd
- use_localtime=YES
- userlist_enable=YES
- userlist_deny=NO
- userlist_file=/etc/vsftpd.user_list
- tcp_wrappers=YES
- reverse_lookup_enable=NO
- pasv_enable=YES
- user_config_dir=/etc/vsftpd/userconf
- listen_address=124.75.29.37