FunkyChicken1970
IS-IT--Management
Hi,
I've been asked to write a script to poll a local folder and upload when there are files present. Whilst this script does the job there's a problem that it crashes after a few hours.. monitoring the task manager under Windows shows that each time files are FTP'd up an additional 4-8k of RAM is used.
I guess my main question is how do I release the memory? It seems that the FTP opperations are chewing up memory on each iteration.. Other comments are more than welcome as Perl is quite new to me but the basic script logic seems OK to me.
Below is the worker loop..
Thanks in advance!
I've been asked to write a script to poll a local folder and upload when there are files present. Whilst this script does the job there's a problem that it crashes after a few hours.. monitoring the task manager under Windows shows that each time files are FTP'd up an additional 4-8k of RAM is used.
I guess my main question is how do I release the memory? It seems that the FTP opperations are chewing up memory on each iteration.. Other comments are more than welcome as Perl is quite new to me but the basic script logic seems OK to me.
Below is the worker loop..
Thanks in advance!
Code:
use POSIX qw(strftime);
#use Time::Local;
use Net::FTP;
#use vars qw/ %opt /;
use File::chdir;
use File::Copy;
#use Getopt::Std;
use Net::SMTP;
$dirroot = "d:\\folder";
$dirout = "d:\\folder\\out";
$dirarchive = "d:\\folder\\archive";
$errors=0;
$smtprecipient = "me\@company.com";
$smtpsender = "report\@company.com";
$smtpserver = '192.168.0.200';
$emailsignature = "-\nEnd of report\n";
@messages = "";
#$today = strftime "%Y%m%d", localtime;
$ftpsite = "ftp.compnay.com";
$ftpusername = "username";
$ftppassword = "password";
##################
($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
$emailsubject = "FTP Upload Process - Started Successfully";
$emailbody = "Upload process has started at " . $hour . ", scheduled to complete at 17:59\n";
email();
$numtrades = 0;
$errors = 0;
$count = 0;
$CWD = $dirout;
while ($hour < 18){
@files = glob "*.swf";
# printf "Waiting for folder contents to stabilise..\n";
sleep (5);
@files = glob "*.swf";
if (@files > 0) {
$ftp = Net::FTP->new($ftpsite, Timeout => 30, Debug => 1);
$ftp->login($ftpusername, $ftppassword) or push(@messages,"Unable to log into FTP site.\nCheck that the login details haven't changed, aborting!\n");
foreach (@files) {
#Upload one file at a time
$ftp->put(@files[$count]) or push(@messages,"Unable to upload " . $filenameupload . ", aborting!\n");
#move to archive folder if verify ok
move (@files[$count], $dirarchive);
$count = $count +1;
} #end of for each files
$ftp->quit;
}
$numtrades = $numtrades + $count;
$count = 0;
@files = -1;
$ftp = -1;
#sleep (55);
}