You are here: Re: ftp_nlist "425 Can't open data connectoin" « All PHP « IT news, forums, messages
Re: ftp_nlist "425 Can't open data connectoin"

Posted by blackpuppy on 08/20/06 10:59

Thanks, Patrick!

It works! ftp_pasv($connect, true) will turns on passive mode so that
the ftp client will initiate the data connection and this will work
around the firewall. Then I enable FTP in the firewall and the script
can work without turning on the passive mode.

There is a further problem when I put the above script in a web page as
shown below.

<HTML>

<HEAD>

<TITLE>

Getting a directory listing with FTP

</TITLE>

</HEAD>



<BODY>

<CENTER>

<H1>Getting a directory listing with FTP</H1>

Here's what's in the remote directory:

<BR>

<BR>

<?php
$ftp_server = "myftpserver";
$connect = ftp_connect($ftp_server)
or die("Couldn't connect to $ftp_server.");
$result = ftp_login($connect, "myftpuser", "mypassword")
or die("Couldn't log in $ftp_server.");
$a = ftp_nlist($connect, "/");
foreach($a as $value){
echo $value, "\n";
}
?>
</CENTER>

<BODY>

</HTML>

Then I access it from Firefox with URL
http://localhost/SpringIntoPHP5/ch09/phpftp.php. The display is:
---------------------------------------------------------
Here's what's in the remote directory:

Couldn't connect to myftpserver.
---------------------------------------------------------

So it fails at ftp_connect($ftp_server) call. Does the PHP FTP
function work differently when running from a web page? Is there
anything related with Firefox? BTW, other examples from this book work
just fine when viewing from Firefox. Or is it because the script is
running under the account apache and this account does not have enough
privilege?

Thanks again!

Patrick Schlangen wrote:
> > - How to make the FTP functions work?
>
> You might need to use PASSIVE ftp mode (e.g. because of firewall or NAT
> settings).
> Just try this:
>
> #! /usr/bin/php
> <?php
> $result = ftp_login($connect, "myftpuser", "mypassword")
> or die("Couldn't log in $ftp_server.");
> ftp_pasv($connect, true);
> $a = ftp_nlist($connect, "/");
> ?>
>
> I just added one line (""ftp_pasv($connect, true);"").
> Please let us know if it works now.
>
> Patrick

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация