Hi,
I am having problems using ftp_nlist and iis.
The problem is if I ftp to a server running vsftpd then I get a directory listing just fine, but if I ftp into an IIS box I get nothing, the connect and cwd command appear in the ftp logs, but not the list command.
My PHP version is 4.3.11-2.8 and is running on apache 2 under fedora core 3.
Any help would be great.
Thanks.
Nathan.
PS: Here is my script(as you can probably tell I a new to PHP, I usualy work in CF)
<?php
require('logfilter_functions.php');
$action=$_GET['ACTION']; //Get action from RODOPI
$ftpurl=$_GET['DIRECTORYURL']; //Get the ftp path from RODOPI
$filemask=$_GET['FILEMASK']; //Get the file format from RODOPI
switch($action){
case 'GETFILELIST':
$ftp_details=ftp_parameters($ftpurl); //convert the URL insto an array
$connection=ftp_connect($ftp_details['host']); //connect to the host
$login_result=ftp_login($connection,$ftp_details['user'],$ftp_details['password']); //logon to the host
if($login_result){ //if login succeeded
ftp_chdir($connection,$ftp_details['path']); //change to the path specified for the files
$files=ftp_nlist($connection,'-l ./'/*.$filemask*/); //list the files that match the file mask
echo '<?xml version=\'1.0\' ?>'.chr(13);
echo '<RODOPI VERSION=\'5.2\'>'.chr(13);
echo ' <FILELIST>'.chr(13);
print_r($files);
foreach($files as $file){
$file=ereg_replace("[[:blank:]]{1,}","|",$file); // replace spaces with a pipe so that we can break the listing into an array
$file_fields=explode("|",$file);
echo ' <FILE '.$file.chr(13).
' URL="'.$file_fields[8].'"'.chr(13).
' CREATION="'.$file_fields[5].' '.$file_fields[6].' '.$file_fields[7].'"'.chr(13).
' MODIFIED="'.$file_fields[5].' '.$file_fields[6].' '.$file_fields[7].'"'.chr(13).
' SIZE="'.$file_fields[4].'"'.chr(13).
' />'.chr(13);
}
echo ' </FILELIST>'.chr(13);
echo '</RODOPI>'.chr(13);
}
ftp_quit($connection);
break;
case 'PARSEFILE':
break;
}
?>
Hmmm.
Maybe code for the included file could be usefull too; Here it is:
<?php
/* Functions for the RODOPI lkog filter script.
Author: Nathan Graham
Author Email: nathan@accc.net.au
Creation Date: 6th January 2006
Modification History:
==========================================
*/
// Function that takes a ftp URL Eg. ftp://user:password@host.com/path/to/files/
// and returns an array with the nescessary parameters to create an ftp connection
// Eg. ftp['user','pass','host','path']
function ftp_parameters($ftpurl){
$newurl=substr($ftpurl,strlen('ftp://'),strlen($ftpurl));
$foundat=strpos($newurl,'@'); // find the @, this is the end of the username and password portion of the URL
if($foundat < 1){ //see if the @ was found, if not the foundat needs to be 1
$foundat=-1;
}else{
$tmp=substr($newurl,0,$foundat); // get the string between ftp:// and @
$tmparray=explode(':',$tmp); // turn this string into an array
$user=$tmparray[0]; // the first array element is the user
$password=$tmparray[1]; // the second is the password
}
$foundslash=strpos($newurl,'/'); // find the / this is the end of the host portion of the URL
$host=substr($newurl,$foundat+1,$foundslash-($foundat+1)); //extract the host portion of the URL
$path=ltrim(substr($newurl,$foundslash,strlen($newurl)-$foundslash),"/"); //the remaining characters are the path
if($path==""){
$path=".";
}
if($user==""){
$user="anonymous";
}
if($password==""){
$password="anonymous";
}
//dump it all to an array
return array('user' => $user,
'password' => $password,
'host' => $host,
'path' => $path);
}
?>