Here is the code i have mocked up to check the root directory and 1 directory down for a dir specified in $mainDirArray and then it will exit out of the loop. $mainBLDirArray are dirs to avoid.
Hope this helps, probably not the most optimised way to do it but works well in testing.
$conn_id1 = ftp_connect($ftp_host);$login_result = ftp_login($conn_id1, $ftp_user, $ftp_pass);
if (!$login_result){
} else {
$mainDirArray = array(0 => 'httpdocs', 'public', 'public_html', 'www', 'html_docs', "web", $domain);
$mainBLDirArray = array(0 => 'maildir', 'logs', 'httpsdocs', 'cgi-bin', 'cgi', 'bin');
$newdir = ftp_nlist($conn_id1, "./");
print_r($newdir);
for($i = 0; $i < count($newdir); ++$i){
for($j = 0; $j < count($mainDirArray); ++$j){
if($newdir[$i] == $mainDirArray[$j]){
$ftp_path = "/".$newdir[$i];
ftp_close($conn_id1);
break 2;
} else {
$ftp_path = "/";
}
}
$newdir2 = ftp_nlist($conn_id1, "./".$newdir[$i]);
for($a = 0; $a < count($newdir2); ++$a){
//check agains blacklist dir list
for($b = 0; $b < count($mainBLDirArray); ++$b){
if(strstr($newdir2[$a], $mainBLDirArray[$b])){
break 2;
} else {
$ftp_path = "/";
}
}
for($b = 0; $b < count($mainDirArray); ++$b){
if(strstr($newdir2[$a], $mainDirArray[$b])){
$ftp_path = "/".$newdir2[$a];
ftp_close($conn_id1);
break 3;
} else {
$ftp_path = "/";
}
}
}
}
}




Recent Comments