Discussion:
ftp_connect returns false
DBW
2004-08-18 01:06:40 UTC
Permalink
Just wondering if someone has some suggestions here.

Using ftp_connect($server, $port) returns a false on the server I am trying
to use. Doesn't matter which server I am trying to connect to. According
to the provider, ftp from the server is allowed and php is compiled with
--enable-ftp

Any ideas/suggestions on what the issue may be?

Catch ya,

DBW
Melbourne | http://ozreef.org/
Australia | ***@ozreef.org
--------------------------------------------------------------------------
When the only tool you own is a hammer, every problem begins to resemble a nail.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jason Wong
2004-08-18 05:08:47 UTC
Permalink
Post by DBW
Just wondering if someone has some suggestions here.
Using ftp_connect($server, $port) returns a false on the server I am trying
to use. Doesn't matter which server I am trying to connect to. According
to the provider, ftp from the server is allowed and php is compiled with
--enable-ftp
Any ideas/suggestions on what the issue may be?
Have you enabled FULL error reporting? Are you getting any errors?

Is the server you're connecting to using a non-standard port? If not just
leave out $port, or make pretty damn sure it's 21.

Do you have shell access to the server? If so you can try using the command
line 'ftp' to see whether you can connect to the ftpserver.

Are you positive that the host allows FTP out of the webserver (the machine
not the program) to a remote ftpserver? Make sure the host knows what you're
trying to do and that they know what they're doing.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
How's it going in those MODULAR LOVE UNITS??
*/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
DBW
2004-08-19 00:36:47 UTC
Permalink
Jason,

Thank you for the reply.
Post by Jason Wong
Have you enabled FULL error reporting? Are you getting any errors?
Here are the couple of lines of interest:

$connection = ftp_connect($server, $port);
$loggedOn = ftp_login($connection, $user, $password);
$systype = ftp_systype($connection);

The error that comes out is:

Warning: ftp_login() expects parameter 1 to be resource, boolean given in
/directory/here/public_html/ftp/index.php on line 108

Warning: ftp_systype() expects parameter 1 to be resource, boolean given in
/directory/here/public_html/ftp/index.php on line 109

Those correspond to the last two lines of the above code.
Post by Jason Wong
Is the server you're connecting to using a non-standard port? If not just
leave out $port, or make pretty damn sure it's 21.
That is set to 21 anyway, but fair enough point.
Post by Jason Wong
Do you have shell access to the server? If so you can try using the command
line 'ftp' to see whether you can connect to the ftpserver.
No, wish I did ;-(
Post by Jason Wong
Are you positive that the host allows FTP out of the webserver (the machine
not the program) to a remote ftpserver? Make sure the host knows what you're
trying to do and that they know what they're doing.
They have told me on two occasions when I asked them that it was allowed to
ftp from the server to others. I am actually trying to ftp to the same
server anyway.

Catch ya,

DBW
Melbourne | http://ozreef.org/
Australia | ***@ozreef.org
--------------------------------------------------------------------------
When the only tool you own is a hammer, every problem begins to resemble a nail.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jason Wong
2004-08-19 03:49:51 UTC
Permalink
Post by DBW
Post by Jason Wong
Have you enabled FULL error reporting? Are you getting any errors?
$connection = ftp_connect($server, $port);
$loggedOn = ftp_login($connection, $user, $password);
$systype = ftp_systype($connection);
Warning: ftp_login() expects parameter 1 to be resource, boolean given in
/directory/here/public_html/ftp/index.php on line 108
Warning: ftp_systype() expects parameter 1 to be resource, boolean given in
/directory/here/public_html/ftp/index.php on line 109
Those correspond to the last two lines of the above code.
Post by Jason Wong
Is the server you're connecting to using a non-standard port? If not just
leave out $port, or make pretty damn sure it's 21.
That is set to 21 anyway, but fair enough point.
OK we've established a couple of things:

1) You have error reporting enabled - this is most important!
2) The ftp functions are compiled in

One thing that you should do when debugging is to plug in static values rather
than using $variables, thus:

$connection = ftp_connect('remote.ftpserver.com', 21);

This will eliminate the cases where your $variables have inadvertently been
changed between them being defined and them being used. And it will eliminate
the cases where you have defined it as $variable and try to use it as
$variabel.

If that is not the problem then the best way to resolve this is to escalate
the issue with your host. There are other tests that can be done which will
help determine whether outgoing FTP is indeed blocked. Eg you can try to ftp
to the webserver itself - this will usually eliminate firewall issues. But it
will be much quicker to work together with your host.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
"I am not sure what this is, but an `F' would only dignify it."
-- English Professor
*/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
DBW
2004-08-19 05:43:05 UTC
Permalink
Jason,

Thanks again for the reply. Much appreciated.

Just to clarify a point, does it matter where you are coming from and
executing the php script? i.e. I am using a browser that is behind a
firewall blocks ftp (hence why I am trying to set up this ftp stuff through
php). I am pretty sure that it doesn't, since I have used other sample
scripts around the web run on their own server and they work fine. Just
want to check to make sure this is actually the case.

Just trying to take it up with my host at the moment. If no joy, shall be
moving on there I think.

Catch ya,

DBW
Melbourne | http://ozreef.org/
Australia | ***@ozreef.org
--------------------------------------------------------------------------
When the only tool you own is a hammer, every problem begins to resemble a nail.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jason Wong
2004-08-19 05:59:45 UTC
Permalink
Post by DBW
Just to clarify a point, does it matter where you are coming from and
executing the php script? i.e. I am using a browser that is behind a
firewall blocks ftp (hence why I am trying to set up this ftp stuff through
php). I am pretty sure that it doesn't, since I have used other sample
scripts around the web run on their own server and they work fine. Just
want to check to make sure this is actually the case.
The ftp connection is made from where the php script resides. Which means on
the webserver. So if the host has blocked outgoing ftp connections from the
webserver you're hosed.

That is why I suggested that you try an ftp connection to the webserver itself
(from the webserver of course):

1) I'm assuming that your host machine has both the webserver installed
(obviously) and that it has an ftpserver (for you put stuff into your
webspace).

2) I'm further assuming that your host has not blocked ftp connections coming
from localhost

Thus if you're able to connect locally then it is a good indication that php's
ftp functions are not a fault, and that it is the host's network
configuration that is preventing you from making outgoing ftp connections.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
He that breaks a thing to find out what it is has left the path of wisdom.
-- J.R.R. Tolkien
*/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Continue reading on narkive:
Loading...