Phil Jackson
08-24-2009, 11:05 PM
Another snippet from my Plug n Play CMS.
This is my bute so be gental!
would also think about increaing max execution time if site is large or running at peak times.
<?php
#created by ACT Web Designs
#luke@actwebdesigns.co.uk
#www.actwebdesigns.co.uk
#please leave in and use as you want
#2009
function storeDirInfo($ftpServer, $ftpUser, $ftpPass)
{
$conn_id = ftp_connect($ftpServer);$login_result = ftp_login ($conn_id, $ftpUser, $ftpPass);$folders = array(".");$done = array();$fileArray = array();$imageArray = array();$file2Array = array();$x=0;while(count($folders)!=0){foreach($folders as $key => $folder){$contents = ftp_nlist($conn_id, $folder);if(!in_array($folder, $done)){foreach($contents as $file){if(!in_array($file."/", $folders) && (!preg_match("#(\.php)|(\.html)|(\.htm)|(\.jpg)|(\.gif)|(\.png)|(\.txt)|(\.js)|(\.css)|(\.\.)|(\.)|(\.bash_logout) |(\.bash_profile)|(\.bashrc)|(\.htaccess)#is", $file))){if(preg_match("#(www)|(public_html)#is", $file, $match)){$folders[] = $file."/";}else{$file2Array[] = $file;}}elseif(!in_array($file, $fileArray)){$fileArray[] = $file;}}$done[] = $folder;}else{unset($folders[$key]);}}$x++;}foreach($done as $key => $folder){if(trim($folder)=="."){unset($done[$key]);}}foreach($done as $key => $folder){if(trim($folder)==".."){unset($done[$key]);}}$z=0;$foldersFound = array();foreach($done as $folder){if(substr($folder, -1)=="/"){$foldersFound[] = $folder;$z++;}}foreach($fileArray as $key => $folder){if(trim($folder)=="."){unset($fileArray[$key]);}}foreach($fileArray as $key => $folder){if(trim($folder)==".."){unset($fileArray[$key]);}}foreach($fileArray as $key => $folder){if(preg_match("#/\.$#is", $folder)){unset($fileArray[$key]);}}foreach($fileArray as $key => $folder){if(preg_match("#/\.\.$#is", $folder)){unset($fileArray[$key]);}}$x=0;$imagesFound = array();foreach($fileArray as $folder){$split = explode(".", $folder);$ext = $split[count($split)-1];if(preg_match("#(jpg)|(gif)|(png)|(bmp)#is", $ext)){$imagesFound[] = $folder;$x++;}}$y=0;$docsFound = array();foreach($fileArray as $folder){$split = explode(".", $folder);$ext = $split[count($split)-1];if(preg_match("#(txt)|(php)|(html)|(htm)|(js)|(css)#is", $ext)){$docsFound[] = $folder;$y++;}}ftp_close($conn_id);return array($foldersFound, $imagesFound, $docsFound);
}
$infoArray = storeDirInfo("ftp.######ftp######.co.uk", "###user#####.co.uk", "###pass#####");
//$infoArray[0] = array of all folders (including full foot)
//$infoArray[0][0] = server root i.e. www | public_html
//$infoArray[1] = array of all images (including full foot)
//$infoArray[2] = array of all documents (including full foot)
?>
output for my site (using print_r):
oops - coding forums didn't like that one:
The text that you have entered is too long (1,37,685 characters). Please shorten it to 20000 characters long.
you get the drift, no matter how deep, how many files, itwill get them! this is the shortened and compressed version, my version stores all info into a database.
EDIT: output here output.txt (http://www.actwebdesigns.co.uk/output.txt)
EDIT: should mention tested on Linux and Windows OS
This is my bute so be gental!
would also think about increaing max execution time if site is large or running at peak times.
<?php
#created by ACT Web Designs
#luke@actwebdesigns.co.uk
#www.actwebdesigns.co.uk
#please leave in and use as you want
#2009
function storeDirInfo($ftpServer, $ftpUser, $ftpPass)
{
$conn_id = ftp_connect($ftpServer);$login_result = ftp_login ($conn_id, $ftpUser, $ftpPass);$folders = array(".");$done = array();$fileArray = array();$imageArray = array();$file2Array = array();$x=0;while(count($folders)!=0){foreach($folders as $key => $folder){$contents = ftp_nlist($conn_id, $folder);if(!in_array($folder, $done)){foreach($contents as $file){if(!in_array($file."/", $folders) && (!preg_match("#(\.php)|(\.html)|(\.htm)|(\.jpg)|(\.gif)|(\.png)|(\.txt)|(\.js)|(\.css)|(\.\.)|(\.)|(\.bash_logout) |(\.bash_profile)|(\.bashrc)|(\.htaccess)#is", $file))){if(preg_match("#(www)|(public_html)#is", $file, $match)){$folders[] = $file."/";}else{$file2Array[] = $file;}}elseif(!in_array($file, $fileArray)){$fileArray[] = $file;}}$done[] = $folder;}else{unset($folders[$key]);}}$x++;}foreach($done as $key => $folder){if(trim($folder)=="."){unset($done[$key]);}}foreach($done as $key => $folder){if(trim($folder)==".."){unset($done[$key]);}}$z=0;$foldersFound = array();foreach($done as $folder){if(substr($folder, -1)=="/"){$foldersFound[] = $folder;$z++;}}foreach($fileArray as $key => $folder){if(trim($folder)=="."){unset($fileArray[$key]);}}foreach($fileArray as $key => $folder){if(trim($folder)==".."){unset($fileArray[$key]);}}foreach($fileArray as $key => $folder){if(preg_match("#/\.$#is", $folder)){unset($fileArray[$key]);}}foreach($fileArray as $key => $folder){if(preg_match("#/\.\.$#is", $folder)){unset($fileArray[$key]);}}$x=0;$imagesFound = array();foreach($fileArray as $folder){$split = explode(".", $folder);$ext = $split[count($split)-1];if(preg_match("#(jpg)|(gif)|(png)|(bmp)#is", $ext)){$imagesFound[] = $folder;$x++;}}$y=0;$docsFound = array();foreach($fileArray as $folder){$split = explode(".", $folder);$ext = $split[count($split)-1];if(preg_match("#(txt)|(php)|(html)|(htm)|(js)|(css)#is", $ext)){$docsFound[] = $folder;$y++;}}ftp_close($conn_id);return array($foldersFound, $imagesFound, $docsFound);
}
$infoArray = storeDirInfo("ftp.######ftp######.co.uk", "###user#####.co.uk", "###pass#####");
//$infoArray[0] = array of all folders (including full foot)
//$infoArray[0][0] = server root i.e. www | public_html
//$infoArray[1] = array of all images (including full foot)
//$infoArray[2] = array of all documents (including full foot)
?>
output for my site (using print_r):
oops - coding forums didn't like that one:
The text that you have entered is too long (1,37,685 characters). Please shorten it to 20000 characters long.
you get the drift, no matter how deep, how many files, itwill get them! this is the shortened and compressed version, my version stores all info into a database.
EDIT: output here output.txt (http://www.actwebdesigns.co.uk/output.txt)
EDIT: should mention tested on Linux and Windows OS