Knowledgebase

Powered by WHMCompleteSolution

Language:

Please Login or Register

 

Knowledgebase Article
Subject: Ban File Extensions Using Pure-ftpd to limit file types
Pure-ftpd has no direct support to prevent files with certain
extensions from being uploaded. But it’s possible to accomplish this
goal using a pure-ftp feature. pure-ftpd has a post-upload program that
runs after each file is successfully uploaded and can run an external
program. Here’s the excerpt from the pure-ftpd manual:



NAME

pure-uploadscript - Automatically run an external program after a successful upload



SYNTAX

pure-uploadscript [-p ] [-B] [-g ] [-h] -r [-u ]



So the program to run in our case can be a simple Bash script I’m going to call ban.sh



#!/bin/bash



uploaded_file=${1};

banned_extensions="zip tar rar";



for ext in ${banned_extensions};

do

count=$(echo ${uploaded_file}|grep -i ${ext}$|wc -l);

if [ "${count}" -gt "0" ];

then

rm -f ${uploaded_file}; # File with banned extension detected. Delete it.

break;

fi;

done



So you start the program in the background like this:



pure-uploadscript -p /var/run/pure-ftpd.pid -B -r /root/ban.sh



More information here: http://linux.die.net/man/8/pure-uploadscript
Back