1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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();
1
2
3
4
5
6
7
foreach( my @entry = readdir DIR ){
if( ((stat(@entry))[9]+604800 <= $zeit) ){
$ftp->rmdir(@entry, RECURSE);
}
}
1
2
3
4
5
6
7
8
9
10
# Lese immer nur einen Eintrag
while ( my $entry = readdir DIR ) {
# . und .. sind zu ignorieren
next if $entry =~ m{^\.\.?$};
if ( (stat($entry))[9]+604800 <= $zeit ) {
# remove $entry and recurse into subdirectories
$ftp->rmdir($entry, 1);
}
}
perldoc Net::FTPrmdir ( DIR [, RECURSE ])
Remove the directory with the name DIR. If RECURSE is true then rmdir will attempt to delete everything inside the directory.
1 2 3 4 5
foreach( my @entry = readdir DIR ){ if( ((stat(@entry))[9]+604800 <= $zeit) ){ $ftp->rmdir(@entry, RECURSE); } }
1 2 3 4 5
while( my $entry = readdir DIR ){ if( ((stat($entry))[9]+604800 <= $zeit) ){ $ftp->rmdir($entry, RECURSE); } }
(stat($entry))[9]
time();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# Lese immer nur einen Eintrag while ( my $entry = readdir DIR ) { # . und .. sind zu ignorieren next if $entry =~ m{^\.\.?$}; my $filetime = ( stat $entry )[9]; my $checktime = $filetime + 604800; # Debug Output print <<"DEBUG"; Zeit (System): $zeit Zeit (Datei): $checktime ( $filetime + 604800 ) Dateiname: $entry DEBUG # raus weil Debugging # if ( (stat($entry))[9]+604800 <= $zeit ) { # # remove $entry and recurse into subdirectories # $ftp->rmdir($entry, 1); # } }