note 76137 added to function.ftp-rawlist

From: Date: Mon, 02 Jul 2007 12:11:22 +0000
Subject: note 76137 added to function.ftp-rawlist
Groups: php.notes 
Request: Send a blank email to php-notes+get-128155@lists.php.net to get a copy of this message
i'v wrote "php ftp recursive" function, you can use in any purposes you like. finally you will get an array of: 1) additional information like time an file's count 2) all files with extensions you defined with paths of course. the function is workable. $values = array( "sitename" => "abc.ru", "ftpserver" => "u12345.ftp.masterhost.ru", "ftpuser" => "u12345", "ftppassword" => "mypassword", "remotedir" => "abc.ru/www" ); function getAllFilesViaFTP($values){ $beginTime = time(); echo "connecting to ".$values['sitename']."\n"; // set up a connection or die if (!$conn_id = ftp_connect($values['ftpserver'])) return ("can't connect to ".$values['ftpserver']."\n"); // try to login if (!@ftp_login($conn_id, $values['ftpuser'], $values['ftppassword'])) echo "can't login to ".$values['sitename']." with entered ".$ftp_user." and password(...) \n"; // get the file list for $values['remotedir'] $fileList = ftp_rawlist($conn_id, $values['remotedir'], TRUE); // print_r($fileList); $fileList_c = count($fileList); $allFiles = $allFilesCount = $allUseFulFilesCount = null; $currentDir = $values['remotedir']; for ($i=0;$i<$fileList_c;$i++){ // change current dir, if current array element is an empty line if (!$fileList[$i]) $currentDir = $fileList[$i+1]; else{ $allFilesCount++; $fileInfo = list() = explode(" ", $fileList[$i]); // print_r($fileInfo); $fileName = $fileInfo[count($fileInfo) - 1]; if (preg_match("/\.php/", $fileName) or preg_match("/\.htm/", $fileName) or preg_match("/\.html/", $fileName)){ $allUseFulFilesCount++; $allFiles[] = preg_replace("/:/", "", $currentDir)."/".$fileName; } } } // close the connection ftp_close($conn_id); // time $fullTime = time() - $beginTime; $result = array ( "allFilesCount" => $allFilesCount, "allUseFulFilesCount" => $allUseFulFilesCount, "fullTime" => $fullTime, "fileList" => $allFiles ); return $result; } $fileList = getAllFilesViaFTP($values); print_r($fileList); ---- Server IP: 195.54.192.44 Probable Submitter: 85.249.87.100 ---- Manual Page -- http://www.php.net/manual/en/function.ftp-rawlist.php Edit -- https://master.php.net/note/edit/76137 Del: integrated -- https://master.php.net/note/delete/76137/integrated Del: useless -- https://master.php.net/note/delete/76137/useless Del: bad code -- https://master.php.net/note/delete/76137/bad+code Del: spam -- https://master.php.net/note/delete/76137/spam Del: non-english -- https://master.php.net/note/delete/76137/non-english Del: in docs -- https://master.php.net/note/delete/76137/in+docs Del: other reasons-- https://master.php.net/note/delete/76137 Reject -- https://master.php.net/note/reject/76137 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128155) next »