php script on Windows hosting does not list ftp files (ftp_rawlist issues)

3.7k views Asked by At

I'm trying to list some files from an external FTP server using php ftp functions on a Windows shared hosting, but I'm having several problems.

I firstly tried with a couple of web applications like ajaxplorer and net2ftp, but I got frustrated and I decided to make a very basic script for testing..

<?php   
$ftp_server = "alinuxftpserver";
$ftp_user = "user";
$ftp_pass = "pass";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// change temp folder (windows)
putenv("TMP=D://inetpub//webs//domain//net2ftp//tmp");
echo getenv('TMP'); 

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) 
{
    echo "Connected as $ftp_user@$ftp_server\n";
} 
else 
{
    echo "Couldn't connect as $ftp_user@$ftp_server\n";
}

if(ftp_pasv( $conn_id, true )) 
      echo "Passive mode, it worked<br/>"; 
    else 
      echo "Passive mode, it didn't work<br/>";

$contents = ftp_rawlist($conn_id, ".");
var_dump($contents);

ftp_close($conn_id);  

die;

?>

On my localhost (linux) it returns an array, while on the windows hosting it returns:

Warning: ftp_rawlist() [function.ftp-rawlist]: php_connect_nonb() failed: No such file or directory (2) in D:\inetpub\webs\domain\ftp.php on line 26
bool(false)

Can't understand.. the directory should be "/" on the external ftp server and of course there are some files & folders (2 folders and 1 file).. In fact on my MAMP installation it works well.

Hosting guys told me that the server configuration is ok.

4

There are 4 answers

1
axiomer On

I'm not 100% sure, but I guess, you should use $contents = ftp_rawlist($conn_id, "/"); instead of $contents = ftp_rawlist($conn_id, ".");

0
Rajiv On

Check your FTP server logs. In my case, the pasv_address was set to a wrong IP address.

0
brunobbmagalhaes On

Better late than never... I had the same problem. With a Linux server everything worked great, but with Windows Server (many versions) we had many problems, including with ftp_nlist() returning an empty array. This worked for us, but I don't know why!

ftp_nlist($handler, '*');
0
Santhosh Fernando On

use ftp_pasv($conn_id, true); some ftp connections will work in passive mode only