473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ftp_nlist "425 Can't open data connectoin"

I am just beginner on PHP. I am reading "Spring Into PHP 5" but cannot
make the ftp examples work.

I am running PHP scripts on a Fedora Core 5 (VMWare virtual machine) on
top of a Windows XP Professional. The PHP version is 5.1.4. The PHP
script is shown below.

#! /usr/bin/php
<?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";
}
?>

I run the above script in a GENOME terminal. It seems it can connect
and log in to the ftp server successfully. But then the ftp_nlist()
call fails. And the server has the following log for this call.
NLST /
150 Opening data channel for directory list.
425 Can't open data connection.
I do not know what is wrong. But in a terminal I can manually log in
the ftp server, and the ls or nlist command will give the file list as
expected. So I suspect the problem is at the PHP ftp function.

The PHP manual on FTP functions
(http://www.php.net/manual/en/ref.ftp.php) has the following
explanation.

"No external libraries are needed to build this extension.

In order to use FTP functions with your PHP configuration, you should
add the --enable-ftp option when installing PHP 4 or greater or
--with-ftp when using PHP 3.

This extension has no configuration directives defined in php.ini."

My questions are:
- How could I know what is wrong with the ftp_nlist() call?
- How could I know if the FTP functions are enabled at PHP
installation?
- How to make the FTP functions work?

Thanks a lot!

Aug 19 '06 #1
3 4503
Hi,
- How could I know if the FTP functions are enabled at PHP
installation?
they are. Otherwise you would get a error about a undefined function.
- 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
$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.");
ftp_pasv($connect, true);
$a = ftp_nlist($connect, "/");
foreach($a as $value){
echo $value, "\n";
}
?>

I just added one line (""ftp_pasv($connect, true);"").
Please let us know if it works now.

Patrick
Aug 19 '06 #2
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
Aug 20 '06 #3
At last it's solved. It's because of SELinux settings.

I am using GNOME. Go to System --Administration --Security Level
and Filewall. Click SELinux tab. Expand "HTTPD Service", and check
"Allow HTTPD scripts and modules to connect to the network". Then
expand "Other", and check "httpd_enable_ftp_server". Finally click OK
button to close the "Security Level Configuration" dialog.

After the above changes, the php web page will work.

Thanks!

blackpuppy wrote:
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!
Aug 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michael | last post by:
I have a problem forcing files to download. If I select Save the document is saved with no problems. If I select "Open" the document is empty or I get a "File not found" error from the application...
3
by: 21novembre | last post by:
Hi all, I made a question several days before to describe my strange trouble of mysqldump. But I still can't figour it out. Well, I just want to ask another question whether I could just backup...
2
by: Jason Morehouse | last post by:
Hello, Anyone know if it's possible to speak with the server via xmlhttp.open while the browser is doing a post -- file upload in this case: <form enctype="multipart/form-data"...
6
by: John Baker | last post by:
Hi: Does "On Open" code execute before or after related data is loaded? I want to test before the form appears on the screen to see if there is any data in the queryresult, and if there is not...
7
by: Aaron G via AccessMonster.com | last post by:
Wanted to share a solution to something which I didn't find on the net: EVERY form in my Microsoft Access 2002 database gave an error any time any code was to be called: form OnOpen, button...
0
by: GS | last post by:
Documentation states that there supposed to be a "Data Sources" windows in VS 2005. See below. I can not find Data menu in VS 2005 anywhere. Anybody sees that menu? Opening the Data Sources Window...
1
by: kbarrios | last post by:
Hi, I am working with VBScript and I put a "window.open" inside a "form action post" due that I am handing a "checkbox" on it, but the "window.open" doesn't work: <FORM...
0
by: Ofelia | last post by:
Hi, I'm new to this forum and to Perl language but I would like to ask for your help. I'm working in Linux and the files I need to process are in the format “file.gz”. I created a script which...
7
kcdoell
by: kcdoell | last post by:
Hello: I have a form that I want to open using a filter that I have created. I have done this usually by pointing the record source of the form to the query/filter that I created. In this new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.