{"id":1013,"date":"2012-09-12T09:13:30","date_gmt":"2012-09-12T14:13:30","guid":{"rendered":"http:\/\/it.thelibrarie.com\/weblog\/?p=1013"},"modified":"2012-09-12T09:13:30","modified_gmt":"2012-09-12T14:13:30","slug":"sftp-email-when-new-file-uploaded","status":"publish","type":"post","link":"https:\/\/it.thelibrarie.com\/weblog\/2012\/09\/sftp-email-when-new-file-uploaded\/","title":{"rendered":"SFTP Email When New File Uploaded"},"content":{"rendered":"<p>I had setup vsftp for SSL (FTPES), but needed a way to send an alert to customer support whenever a file had been uploaded.  Otherwise the support staff would need to manually check each customer&#8217;s folders to see if anything new had arrived.<\/p>\n<p><strong>Install Dnotify<\/strong><br \/>\n<code>apt-get install dnotify<\/code><\/p>\n<p><strong>Create your startup script<\/strong><br \/>\n<code>nano \/dnotify.sh<\/code><\/p>\n<blockquote><p>dnotify -b -p 1 -r -C \/home\/ -e \/email.sh {}<\/p><\/blockquote>\n<p>This will run dnotify in the -b background, no more than one -p process, -r recursive folder (subfolders), -C for file creations only, -e execute the following script.<\/p>\n<p><strong>Create your email script<\/strong><br \/>\n<code>nano \/email.sh<\/code><\/p>\n<blockquote><p>#!\/bin\/bash<br \/>\nDIR=&#8221;$1&#8243;<br \/>\nrm \/upload.txt<br \/>\necho &#8220;Dear User,&#8221;>>\/upload.txt<br \/>\necho &#8220;A new file has been uploaded to the $DIR directory&#8221;>>\/upload.txt<br \/>\ncat \/upload.txt | mailx -s &#8220;New FTP File Upload&#8221; customersupport@domain.tld<\/p><\/blockquote>\n<p><strong>Make both scripts run-able<\/strong><br \/>\n<code>chmod +x email.sh<\/code><br \/>\n<code>chmod +x dnotify.sh<\/code><\/p>\n<p><strong>Run the script and test<\/strong><br \/>\n<code>.\/dnotify.sh<\/code><br \/>\nUpload a file using FTP\/WinSCP\/WGET or another method to any of the folders you&#8217;re searching (my script searches all of \/home and subfolders).<\/p>\n<p>I added this as a startup script.<\/p>\n<p>I got most of my help from <a href=\"http:\/\/nixcraft.com\/ubuntu-debian\/13163-ubuntu-linux-file-upload-creation-email-notification-2.html\" title=\"Nixcraft\" target=\"_blank\">nixcraft<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had setup vsftp for SSL (FTPES), but needed a way to send an alert to customer support whenever a file had been uploaded. Otherwise the support staff would need to manually check each customer&#8217;s folders to see if anything new had arrived. Install Dnotify apt-get install dnotify Create your startup script nano \/dnotify.sh dnotify &hellip; <a href=\"https:\/\/it.thelibrarie.com\/weblog\/2012\/09\/sftp-email-when-new-file-uploaded\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">SFTP Email When New File Uploaded<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1013","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/comments?post=1013"}],"version-history":[{"count":1,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":1014,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/posts\/1013\/revisions\/1014"}],"wp:attachment":[{"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/media?parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/categories?post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it.thelibrarie.com\/weblog\/wp-json\/wp\/v2\/tags?post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}