#!/usr/local/bin/perl

##################################################################
$WrittenBy = "Arther Neal Garrett";                               
     $Date = "Oct 19, 2004";                                      
  $Version = "v1.0";                                              
##################################################################

use Net::FTP;

$username = "UserName";
$password = "Password";
@hosts = qw(192.168.0.1 192.168.0.2 192.168.0.3);
@watchlist = qw(MyScript.pl MyPerlTest.pl MyPerl.pl); 

#Initialize
$last = 1;$mtime = 0;$i = 1;

while ($i > 0) {
	foreach $watchfile(@watchlist) {
		chomp($watchfile);
		($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks)= stat("$watchfile");
		if ($i == 1) {$last = $mtime;}
		if($mtime > $last) {&FTPPUT;$last = $mtime;}
	}
	$i = ($i +1);
	sleep 1;
}

sub FTPPUT {
	foreach $hostname(@hosts) {
		chomp($hostname);
		$ERRX = 0;
		@ftplog = $ftp = Net::FTP->new("$hostname", Port => 21, Debug => 0, Timeout => 15,) or &ERROR("Can't FTP to $hostname\n");
		$ftp->login("$username","$password") or &ERROR("$username DENIED access to $hostname.\n");
		$ftp->binary();
		$ftp->cwd("/netexpert/netexpert_vsm5.0/Custom/NETEXPORT") or &ERROR("cwd change directory failed\n");
		$ftp->put("$watchfile") or &ERROR("$watchfile transfer to $hostname failed\n");
		$ftp->quit;
		$ftptime = localtime();
		unless($ERRX) {
			print "$watchfile ftp\'d to $hostname\t $ftptime\n";
		}
	}
}

sub ERROR {	
	unless($ERRX) {
		warn "ERROR: @_";
		$ERRX = 1;
	}
}
	