HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (
-   Suggest HOWTO (
-   -   PureFTP that send email notification on Upload (

almeister9 20th November 2009 08:08

[RESOLVED] PureFTP that send email notification on Upload
Hi All,

I am trying to piece together little snippets from all over the place to get this to work and I just cant get it to work.

What I want is a stand alone FTP server that sends an email to me when a file is uploaded.

I have started by building an Ubuntu 9.04 server as per Falkos:
up to step 10 and then adding postfix

Then installing Pure-FTP as per Falkos:

I then try to enable the pure-uploadscript by donig this (found on the net):
Step 1:
vi /etc/default/pure-ftpd-common
Run Pure-FTPd in standalone mode (not inetd mode).
Change the option "STANDALONE_OR_INETD" to "STANDALONE" in

Step 2: Tell Pure-FTPd the user ID under which the script should be run. Pure doesn't like usernames, so you have to provide the numeric UID. In case of www-data it is UID 33.
# if set, pure-uploadscript will spawn $UPLOADSCRIPT running as the # given uid and gid UPLOADUID=2001
Step 3: Tell pure-ftpd where the script is located: Change the option UPLOADSCRIPT in /etc/default/pure-ftpd.
# example: UPLOADSCRIPT=/usr/local/sbin/ UPLOADSCRIPT=/usr/local/sbin/

Step 4: Enable the option itself:
echo "yes" > /etc/pure-ftpd/conf/CallUploadScript
Step 5: Start or Restart Pure-ftpd
/etc/init.d/pure-ftpd-mysql restart

And then I made my first ever shell script which went like this:
echo "$1 uploaded" | mail -s "New Upload : $1"

but It doesn't work.

FTP Server part of things works fine.

The only function that the mailer side of this needs to be able to do is send me an email when a file is uploaded. It needs no incoming mailboxes or anything like that.
The Server is a FTP server and nothing else.
It sits in our office so it could even send me a message across the network if that is possible, but I use a windows machine(Windows 7) and a mac (OSX 10.4) as a pair of work stations.

If someone could show me a concise way of istalling Pure-FTP on an Ubuntu 9.04 server with upload notification, I would be very appreciative.

Cheers AL.

falko 21st November 2009 10:46


Originally Posted by almeister9 (Post 211358)
And then I made my first ever shell script which went like this:
echo "$1 uploaded" | mail -s "New Upload : $1"

but It doesn't work.

Have you tried to use the full path for the mail command?

almeister9 22nd November 2009 16:10


Have you tried to use the full path for the mail command?
I'm sorry Falko, but I don't know what the full path for the mail command is.

I am trying to learn about the linux world but I find man pages especially unhelpful for newbs and information on this topic, I have found particulary difficult to find.

I am about to start trying the snail program or ssmtp. As far as I can tell, these don't need a mail server installed on the system, they just use an external mail server and account. (It will also make me feel safer not having a mail server on the system to worry about being compromised. I don't know enough to make it secure.)

I am hoping that I can find an example of a script that uses one of these programs that will work for me or that I can some how work it out by gathering clues.

almeister9 23rd November 2009 07:19

The Ultra Elusive pure-uploadscript(8)
I have now started again from scratch.
I have an Ubuntu 9.04 32-bit server as Falko's:
up to stage 10.
with a working Pure-ftpd server as per Falkos:

I then installed ssmtp:
sudo apt-get install ssmtp

and configured:
sudo vi /etc/ssmtp/ssmtp.conf


Then by typing into terminal:
ssmtp and hitting enter, then
Subject: test email

hello world!

and then crtl+D it successfully sends a mail via my gmail account.


I edit Pure-ftp conf file:
vi /etc/default/pure-ftpd-common

and make sure option "STANDALONE_OR_INETD" is "STANDALONE"
(because it said to on the man page)

All that above I got from one of the very few sources I could find on the internet and it basically said "then create a script that does something useful and you are done.
This did not eaxctly help me.
I persisted:
vi /usr/local/sbin/

#! /bin/sh
echo "$1 uploaded" | ssmtp
Subject: New File Uploaded

"$1 uploaded"

No Dice
I found another source that gave a small amount of help:
which said:
Step 6: Check if the daemon really run with the new options. (Doesn't say how)

root 18623 0.0 0.0 12120 868 ? Ss 19:39 0:00 pure-ftpd (SERVER) www-data 18671 0.0 0.0 11912 672 ? Ss 19:40 0:00 /usr/sbin/pure-uploadscript -r /usr/local/sbin/ -B -u 33 -g 33
Don't know what that means
Step 7: Create a test script. E.g. this one will write the filename to a file called /tmp/pure-was-here<datestamp>.

#!/bin/sh echo "$1" > /tmp/pure-was-here$(date +%Y%m%d%H%M%S)
Step 8: Test the script, log in via ftp and upload a file:
I tried that and uploaded a file but the file in /TEMP/ doesn't get created.

I have read the man page for pure-uploadscript over and over but it doesn't seem to tell me how to do anything, just what it can do.

I assume that what I need to do now is:
1). Learn how to create a shell script and then place it somewhere and tell the conf page where it is (UPLOADSCRIPT=)
2). Learn how to get said shell script to use ssmtp to send an email using the available things passed from uploadscript ($1 and others ???)
3). Prey that it works because if it doesn't I have no where to turn.

I feel I am so close now,

Any help that any kind soul could lend me would be greatly appreciated.

Cheers Al.

falko 23rd November 2009 15:13

What are the outputs of

which mail

which ssmtp

almeister9 24th November 2009 00:35

Hi Falko,
Thanks for looking at this for me.

The output of "which mail" is nothing.

The output of "which ssmtp" is:

When I started again from scratch, I built it with just the server and Pureftp, then installed ssmtp. Thats why "which mail" is empty.

Following your first advice

Have you tried to use the full path for the mail command?
would that mean that the script should read:

echo "$1 uploaded" | /usr/sbin/ssmtp
From: originating@address
Subject: "New Upload : $1"

Body text with hopefully some of the other arguments passed from the pure-uploadscript

And also, does the script need to have a .sh file extension?

Thanks again for any help you can give me with this.
Cheers Al.

almeister9 24th November 2009 03:07

A little further
I have made a little more progress.
I have changed /etc/default/pure-ftpd-common to read
This is the userID of pureftpd.
I then made a script called /usr/sbin/ which has the following code:

echo "$1" > /tmp/pure-was-here$(date +%Y%m%d%H%M%S)

I then did this

chmod +x
and restarted Pureftpd.
I then uploaded a file to the ftp server and went to /tmp and the file was there!! YAY!
So I made a txt file called /usr/sbin/msg1.txt which contains:

To: recipient@address
From: Originating@address
Subject: Test from FTP Server

This is a test

then created a script called /usr/sbin/ which contains:

ssmtp < msg1.txt
and I ran

chmod +x
then restarted PureFTPd.

This however does not work.
If I move to the containing folder
cd /usr/sbin
and type ./
The email IS sent.

I feel I am very close now but it is still not working.

almeister9 24th November 2009 08:10

Using this script I found at


ssmtp -oi << EOF
From: FTP Server <>
Subject: File uploaded to FTP SERVER on $CURDATE

The file $1 was uploaded to the FTP-SERVER on $CURDATE.


$1 is the argument passed from pure-uploadscript(8) so the email I got says:

The file home/ was uploaded ...

YAY double YAY
and thanks to for the script

All times are GMT +2. The time now is 05:23.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.