#!/bin/bash
 
#This Scrips uploades the last Picture to an FTP Server
#Can be used for Zipabox, if your Camera creates Directorys what is denied by Zipato
#Script by derhelle (info@control-your-home.de) Version 0.2  27.01.2015


#Directory of the Camera Pics
HOME='XXXXXX'

#FTP Server
FTPSERVER='my.zipato.com'

#Username
USER='XXXXXXX'

#Password
PASSWD='XXXXXXXXX'
 
#Get the latest Image
campic=$(find $HOME -type f -printf '%T@ %p\n' | grep jpg | sort -n | tail -1 | cut -f2- -d" ")

#If there is no File
if [ -z  "$campic" ] 
then echo "No Pictures in DIR"; exit 1
else

#Upload the Latest Pic
lftp -e "put $campic; bye" -u $USER,$PASSWD $FTPSERVER

#If you want to delete all Pictures in the Dir use this one ATENTTION: all Files in $HOME will be deleted
rm -rf $HOME*

#If you want to delete only the uploaded Pic, use this
#rm $campic

fi
