use strict; use Net::FTP; my $host = "*********"; my $username = "********"; my $password = "********"; my $directory = "/var/backup/"; my $ftp = Net::FTP->new($host, Debug => 1); if(defined($ftp)){ $ftp->login($username, $password); $ftp->binary(); $ftp->cwd($directory); my $zeit = time(); opendir DIR, $directory or die $!; foreach( my @entry = readdir DIR ){ if( ((stat(@entry))[9]+604800 <= $zeit) ){ $ftp->rmdir(@entry, RECURSE); } } closedir DIR; } $ftp->quit();