Skip to content

Disk quotas

uFTP has no quota of its own. The file system of your system already does it better, for every program and not only for the FTP server, and the cases where it matters (a customer that must not use more than 10 GB) are covered by what the operating system offers. This page says what to use. The commands are examples: check them against the documentation of your distribution before you rely on them, and try them on a test folder. They have not been tested with uFTP in this guide.

What uFTP does by itself

  • MIN_FREE_SPACE_MB protects the disk of the system: an upload is refused with 452 when the free space is below that many megabytes, and one that is going on is stopped. See Configuration.
  • When a write fails because the disk is full or a quota is exceeded, the upload stops with 451 and the log says why: STOR /path failed after 1048576 bytes: write error: Disk quota exceeded (or No space left on device). The part of the file that was written stays.

What to use

You want Use Notes
A limit for a folder tree, whoever owns the files Project quotas of XFS or ext4 The best fit for uFTP: the limit follows the folder, not the owner of the files
A limit for a customer, simple and for any file system A separate file system: a partition, a logical volume, or an image file mounted as a loop device When it is full the writes fail, and nothing else on the machine is affected
A folder that is a unit of its own A btrfs subvolume with a qgroup limit, or a ZFS dataset with a quota If you already use these file systems
A limit per user (usrquota) Not a good match See the note below

Project quotas on XFS

# mount the file system with project quotas (in /etc/fstab: the option prjquota), then
echo "42:/srv/ftp/customer1"  | sudo tee -a /etc/projects
echo "customer1:42"           | sudo tee -a /etc/projid
sudo xfs_quota -x -c 'project -s customer1' /srv
sudo xfs_quota -x -c 'limit -p bhard=10g customer1' /srv
sudo xfs_quota -x -c 'report -p -h' /srv

Project quotas on ext4

The file system needs the quota feature with project quotas (kernel 4.5 or later), made while it is not mounted, and the mount option prjquota:

sudo tune2fs -O quota -Q prjquota /dev/sdb1
# mount it with the option prjquota, then give the folder a project and a limit
sudo chattr -p 42 +P /srv/ftp/customer1
sudo setquota -P 42 0 10485760 0 0 /srv        # block hard limit in 1 KiB blocks (10 GiB)
sudo repquota -P /srv

A separate file system for a customer

sudo truncate -s 10G /srv/images/customer1.img
sudo mkfs.ext4 -F /srv/images/customer1.img
sudo mkdir -p /srv/ftp/customer1
sudo mount -o loop /srv/images/customer1.img /srv/ftp/customer1      # and a line in /etc/fstab to keep it
sudo chown uftp:uftp /srv/ftp/customer1

btrfs and ZFS

# btrfs: a subvolume per customer with a limit
sudo btrfs subvolume create /srv/ftp/customer1
sudo btrfs quota enable /srv/ftp
sudo btrfs qgroup limit 10G /srv/ftp/customer1

# ZFS: a dataset per customer with a quota
sudo zfs create -o quota=10G pool/ftp/customer1

A note on quotas per user (usrquota)

The quotas of the system by user count the files that belong to that user. uFTP creates a file as the user that runs it (uftp, or root), and gives it to the owner of the FTP user (USER_NAME_OWNER_n) only at the end of the upload, and only when it runs as root. So a quota per user would not stop an upload while it is in progress, and it needs a system user for each FTP user. Project quotas or a separate file system do not have this problem.

In Docker

Put the folder of the files (/srv/ftp) on a volume that lives on a file system with a limit: one of the images above mounted on the host and passed to the container (-v /srv/ftp/customer1:/srv/ftp), or a volume on XFS with project quotas. See Run in Docker.