#!/usr/bin/perl 

#use CGI ':standard';
use DBI;
use Net::FTP;

($sec,$min,$hour,$mday,$monn,$yearn,$wday,$yday,$isdst) = localtime(time());
open DATA, "/var/www/termo/day.dat";
@day=<DATA>;
close DATA;
$newdata=0;
if ($day[0]!=$mday){$newdata=1;
    open DATA, ">/var/www/termo/day.dat";
    print DATA "$mday";
    close DATA;
}



$ftp = Net::FTP->new("77.222.40.195", Timeout => 30, Debug => 0, Passive=>0) || die "Can't connect to ftp server1.\n";
$ftp->login("kandalinfo_termo", "serterser") || die "Can't login to ftp server.\n";
$ftp->binary();
if ($newdata==1){
    $ftp->delete("termo_old.png");$ftp->rename("termo.png","termo_old.png");
    $ftp->delete("pressure_old.png");$ftp->rename("pressure.png","pressure_old.png");
    $ftp->delete("Humidity_old.png");$ftp->rename("Humidity.png","Humidity_old.png");
    }
else {$ftp->delete("termo.png");}
$ftp->put("/var/www/termo/termo.png","termo.png") || die "Can't connect: $@\n";
$ftp->delete("termo_3d.png");
$ftp->put("/var/www/termo/termo_3d.png","termo_3d.png") || die "Can't connect: $@\n";
$ftp->delete("pressure.png");
$ftp->put("/var/www/termo/pressure.png","pressure.png") || die "Can't connect: $@\n";
$ftp->delete("pressure_3d.png");
$ftp->put("/var/www/termo/pressure_3d.png","pressure_3d.png") || die "Can't connect: $@\n";
$ftp->delete("Humidity.png");
$ftp->put("/var/www/termo/Humidity.png","Humidity.png") || die "Can't connect: $@\n";
$ftp->delete("Humidity_3d.png");
$ftp->put("/var/www/termo/Humidity_3d.png","Humidity_3d.png") || die "Can't connect: $@\n";
$ftp->quit();

