SunQuest
           FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old September 19th, 2003, 08:59 AM
graphics34 graphics34 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 graphics34 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy watch ftp directory email when new file arrives

Hi all, new to this found this script and i am trying to get it to work with our sytem. All I want is an email when the ftp directory changes. I dont need to know the file name(but would be nice). I have tried the script with sleeptime because it should loop but it doesnt work. I have tried with crond setting up for every 5 minutes, but all it does is give me an email every 5 minutes.
Email part works just removed my settings. Any help would be appreciated.
Here is code I used with crond
#!/usr/bin/perl
my $dir = "/home/www/ftp";
my $sendto = "someone@somewhere.com";
my $sendfrom = "someone@somewhere.com";
my $sendsubject = "you have ftp!";
my $sendmessage = "it works";
my $mail = "/usr/sbin/sendmail";

#### you shouldn't need to change anything below here
my @lastfiles;
my $sendmail = "no";
while ( -e "$dir" ) {
opendir(DIR,$dir);
my @files = readdir(DIR);
closedir(DIR);
foreach(@files) {
if ( ! grep(/$_/,@lastfiles) ) {
$sendmail = "yes"; ## didn't see this file last
## time, so send email
push(@lastfiles,$_); ## add this filename so we
## don't send mail over it next time
}
}
if ( $sendmail eq "yes" ) {
open(SENDMAIL, "| /usr/sbin/sendmail -t") || die "Unable to open sendmail";
print SENDMAIL "From: someone\@somewhere.com\r\n";
print SENDMAIL "To: someone\@somewhere.com\r\n";
print SENDMAIL "Reply-To: someone\@somewhere.com\r\n";
print SENDMAIL "Subject: You Have a new ftp file\r\n";
print SENDMAIL " Please Check ftp site\r\n";
close(SENDMAIL);
}
$sendmail = "no";
}

Reply With Quote
  #2  
Old September 19th, 2003, 09:29 AM
ishnid's Avatar
ishnid ishnid is offline
kill 9, $$;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Sep 2001
Location: Dublin, Eire
Posts: 5,509 ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level)ishnid User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 17 h 33 m 15 sec
Reputation Power: 1322
As it has been pointed out in a different thread this week, it's preferable to use cron rather than having a process constantly running.

I would suggest running a script every 5 minutes that checks all the files in your directory to see if they've been modified in the last 5 minutes (see the stat function) , sending you an email with details if any have.

The reason running your script under cron every 5 mins sends you an email anyway is because initially, @lastfiles is empty, so if it finds anything at all, it'll send the mail.

That script could cause memory problems if you leave it running. It keeps adding to @lastfiles as it finds new files. Over time, this array will get bigger and bigger, causing problems eventually unless you stop and restart the process, at which time it will pick up all the files in your dir as being new.

The other prob with it is that if somebody uploads a newer version of an existing file (with the same filename), the script won't catch that because it already has that filename in @lastfiles.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > watch ftp directory email when new file arrives


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway