For the complete documentation index, see llms.txt. This page is also available as Markdown.

36.3 ProFTPD (with MySQL)

Tip

Connecting to a ProFTPD server using the built-in Windows FTP client will not produce garbled text.

Installing ProFTPD

Note

This section is based on MySQL 8.0. For MySQL installation and basic setup, please refer to other chapters.

Please complete the installation and configuration of MySQL 8.x on your own, and ensure that its version is consistent with the databases/mysql8X-client version installed by proftpd-mod_sql_mysql.

Install ProFTPD and its MySQL module:

# pkg install proftpd proftpd-mod_sql_mysql

Or install using Ports:

# cd /usr/ports/ftp/proftpd/ && make install clean
# cd /usr/ports/databases/proftpd-mod_sql_mysql/ && make install clean

ProFTPD Configuration File

Edit the ProFTPD configuration file /usr/local/etc/proftpd.conf:

Tip

See the sample file at /usr/local/etc/proftpd.conf.sample.

ServerName "Test Ftp Server"                     # FTP server name
ServerType standalone                             # Standalone mode
DefaultServer on                                  # Set as default server
ServerIdent on "FTP Server ready"                # Server identification information
Port 21                                          # Listening port
Umask 022                                        # File creation mask

# Timeout settings
TimeoutLogin 300                                 # Login timeout (seconds)
TimeoutIdle 36000                                # Idle timeout (seconds)
TimeoutNoTransfer 36000                          # No-transfer timeout (seconds)

# Resource limits
User proftpd                                     # Service running user
Group proftpd                                    # Service running group
RLimitMemory 256M 256M                           # Memory limit
RLimitOpenFiles 1024 1024                        # Open file count limit
PassivePorts 50000 60000                          # Passive mode port range

# Log configuration
LogFormat default "%h %l %u %t \"%r\" %s %b"     # Default log format
LogFormat auth "%v [%P] %h %t \"%r\" %s"         # Authentication log format
SystemLog /var/log/proftpd/proftpd.log           # System log path
TransferLog /var/log/proftpd/xfer.log            # File transfer log path
ExtendedLog /var/log/proftpd/auth.log AUTH auth  # Extended authentication log

# MySQL module loading
LoadModule mod_sql.c
LoadModule mod_sql_mysql.c
LoadModule mod_sql_passwd.c

# Only allow access to respective directories
DefaultRoot ~                                    # Restrict users to their home directory

# Allow file overwriting
AllowOverwrite on                                # Allow file overwrite

<Global>
  # Database connection
  SQLConnectInfo proftpd@localhost proftpd <your_database_password>   # Database connection info (user, host, password)

  # Password authentication settings
  SQLAuthTypes SHA256                             # Use SHA256 encrypted authentication
  SQLPasswordEngine on                            # Enable SQL password engine

  # User table mapping
  SQLUserInfo users username password uid gid homedir shell   # Map users table fields
  SQLDefaultGID 2000                              # Default GID
  SQLDefaultUID 2000                              # Default UID
  RequireValidShell off                            # Do not require a valid shell

  # Authentication order
  AuthOrder mod_sql.c
  SQLAuthenticate users                            # Use SQL user table for authentication

  # Login statistics
  SQLNamedQuery getcount SELECT "CONCAT('Total logins: ', count) FROM users WHERE username='%u'"   # Query login count
  SQLNamedQuery updatecount UPDATE "count=count+1 WHERE username='%u'" users                       # Update login count
  SQLShowInfo PASS "230" "%{getcount}"              # Display login statistics
  SQLLog PASS updatecount                            # Record login statistics

  # File operation logging
  SQLNamedQuery log_work FREEFORM "INSERT INTO worklog (user_name, file_and_path, bytes, send_time, client_ip, client_name, client_command) VALUES ('%u', '%f', %b, NULLIF('%T', ''), '%a', '%h', '%m')"  # File operation log record
  SQLLog RETR,STOR,DELE log_work                    # Log RETR, STOR, DELE operations to the worklog table
</Global>

Create the log directory:

Warning

If the directory is not manually created, the system will display proftpd[3435]: warning: handling possibly truncated configuration data at line 65 of '/usr/local/etc/proftpd.conf'.

Tip

The ProFTPD configuration file /usr/local/etc/proftpd.conf has a syntax check command: proftpd -t -d5.

In this configuration, the server uses port 21 for active mode and ports 50000-60000 for passive mode. Ensure that the firewall allows these ports.

For the PF firewall, use the following rule:

Allow inbound TCP traffic from the external interface $ext_if (replace with the actual network interface) to local ports 21 and 50000-60000:

Creating Users

For security reasons, ProFTPD should be run as a non-root user. Add a new user:

MySQL Database Setup

Create the MySQL database and user:

Create the database user and password:

Create data tables:

The following has been created:

Item
Value

FTP username

test

FTP login password

FTPpassword_here

UID

1002

GID

1002

Warning

The UID and GID above must match those of the proftpd user, otherwise there will only be read permission without write permission.

You can obtain the UID, GID, and group information for the proftpd user using:

Test the database connection:

Create the directory and test the FTP user:

Service Operations

After configuration is complete, start and manage the ProFTPD service:

Log in to FTP with the username test and the password FTPpassword_here.

Last updated