-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftp_prune.php
53 lines (36 loc) · 1.11 KB
/
ftp_prune.php
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
echo 'Prune<br>';
// set up basic connection
$conn_id = ftp_connect($ipAddress);
// login with username and password
$login_result = ftp_login($conn_id, $userName, $passWord);
$path2 = ''; //local relative directory
$path1 = ''; //remote relative directory
$objects_dest = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path2), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects_dest as $name_source => $object){
$findme = '\.';
$pos = strpos($name_source, $findme);
if ($pos === false) {
if (is_file($name_source)) {
$name_dest = substr($name_source, 14);
echo $name_dest.'<br>';
if (file_exists($name_source)){
echo $name_source.'<br>';
$res = ftp_size($conn_id, $name_dest);
if ($res != -1) {
echo "size of $name_source is $res bytes<br>";
} else {
echo "couldn't get the size<br>";
// Use unlink() function to delete a file
if (!unlink($name_source)) {
echo ("$name_source cannot be deleted due to an error");
}
else {
echo ("$name_source has been deleted");
}
}
}
}
}
}
?>