pihaih
Posts: 20
Joined: Tue Feb 19, 2013 10:10 pm

Alert on FTP upload ?

Sun May 26, 2013 12:16 pm

Hi
I want to use one of my pi as FTP server to store pictures sent by a webcam.
Installed proftpd with default settings, camera saves pictures there already, works well so far

Here is the question I have
How can I make the pi sending an e-mail with the URL of the saved file, so I simply can click on it to view it on my smartphone?
At the final stage pi will be accessed through dyndns, so I should be able to add the hostname:port rather than the ip address to the url.
thanks for any help

pihaih

PS: Keep in mind...I am into redmond products since the beginning, but a total newbie to pi, but starting to like this little thing big time, so talk in simple terms to me please :D

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Alert on FTP upload ?

Sun May 26, 2013 12:25 pm

if I understand correctly you want the Pi to

1) recognise that a new file has arrived in a (ftp) directory.
2) e-mail the file's url to a fixed e-mail address

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Alert on FTP upload ?

Sun May 26, 2013 12:28 pm

joan wrote:if I understand correctly you want the Pi to

1) recognise that a new file has arrived in a (ftp) directory.
2) e-mail the file's url to a fixed e-mail address
Assuming this assumption is correct...

There are 2 ways to do it - the easy way and the hard way.

1) The easy way: Write a process that polls - i.e., loops every (say) 30 seconds, checking for a new file and sends the email when it detects one.

2) The hard way: Look into the "file system notification events" stuff (which I've never done, although I looked at it briefly once and it looked not all that complicated) and then you can do it without polling.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

pihaih
Posts: 20
Joined: Tue Feb 19, 2013 10:10 pm

Re: Alert on FTP upload ?

Sun May 26, 2013 12:38 pm

joan wrote:if I understand correctly you want the Pi to

1) recognise that a new file has arrived in a (ftp) directory.
2) e-mail the file's url to a fixed e-mail address
you understand 100% correct, where sending the url to two (or more) e-mail addresses would be perfect

pihaih
Posts: 20
Joined: Tue Feb 19, 2013 10:10 pm

Re: Alert on FTP upload ?

Sun May 26, 2013 12:40 pm

Joe Schmoe wrote:
joan wrote:if I understand correctly you want the Pi to

1) recognise that a new file has arrived in a (ftp) directory.
2) e-mail the file's url to a fixed e-mail address
Assuming this assumption is correct...

There are 2 ways to do it - the easy way and the hard way.

1) The easy way: Write a process that polls - i.e., loops every (say) 30 seconds, checking for a new file and sends the email when it detects one.

2) The hard way: Look into the "file system notification events" stuff (which I've never done, although I looked at it briefly once and it looked not all that complicated) and then you can do it without polling.
Well as a total newbie I guess even the easy way is too hard for me, at least is sounds like... :)
Is there a "how-to" available so I could try to learn, and is there a chance to do so with zero linux knowledge?

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Alert on FTP upload ?

Sun May 26, 2013 4:42 pm

The sort of proper way is to use inotify which raises a notification when files change in a directory.

sudo apt-get install inotify-tools

Then create an executable script along the following lines, modifying your-ftp-directory, your-domain, and your-email-address.

Code: Select all

#!/bin/bash
while true
do
   FILE=$(inotifywait -q -e close_write,moved_to --format "%f" your-ftp-directory)
   T=`mktemp`
   D=`date`
   echo "http://your-domain/your-dir/$FILE" >$T
   mail -s "$FILE added at $D" your-email-address <$T
   rm $T
done
Assuming you call the script notify then

chmod +x notify

To run the script in the background do

./notify &

To kill the script

killall notify

This assumes you have mail working on the Pi.

If you don't have mail working it may be sufficient to


sudo apt-get install sendmail
sudo apt-get install bsd-mailx

pihaih
Posts: 20
Joined: Tue Feb 19, 2013 10:10 pm

Re: Alert on FTP upload ?

Sun May 26, 2013 6:39 pm

Thanks a lot,
I'll start with the mail first and then try to get the script going

Return to “General discussion”