An Entrepreneur, Coach, IT Consultant, Strategic Adviser, and a Traveler craving to explore and contribute to forming a better society.

Tuesday, December 2, 2008

PHP Function: isFTPFileExists (Searching a FILE in FTP)

No comments :
Keywords: PHP, LAMP, FTP, isFTPFileExists, PHP Functions, Searching a file in FTP

Following is the PHP function, help you search a file in the FTP Location:-

Note: FTP location shud be allowed to be accessed anonymously.

function isFTPFileExists( ){

$url ="http://www.yourftpwebsite.com/path.php"; 
$ch = curl_init() or die( "Cant connect to the FTP SITE - ". curl_error( ) ); 
curl_setopt( $ch, CURLOPT_URL, $url ); 
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); 

$file = curl_exec( $ch ) or die( curl_error( ) );

$h1tags = preg_match_all( "/()(\w.*)(<\/h1>)/isxmU", $file, $patterns );
$result = array( );
array_push( $result, $patterns[ 2 ] ); 
array_push( $result, count( $patterns[ 2 ] ) ); 

if( $result[ 0 ] [ 0 ] == "Not Found" ){ 
   
   return "Please try Again with some other keyword/filename"; 

}else{ 
   
   return "Link Not Found in the given URL"; 


curl_error($ch); 
curl_close($ch); 

}

Keywords: PHP, LAMP, FTP, isFTPFileExists, PHP Functions, Searching a file in FTP

No comments :