Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Response from FTP server?

Status
Not open for further replies.

tweenerz

Programmer
Mar 25, 2002
202
US
I am using the native php ftp functions and noticed there doesn't seem to be a way to get the actual response back from the server I am connecting to (or trying to). Most or all of the functions simply return a boolean value.

It would be nice to know what the actual response from the server is to figure out the problem. I have used lower level sockets connections to perform the ftp functions and was able to get the response that way via fgets, but in rare cases, the connection would hang, so I'm reverting back to the native functions.

So does anyone know if I can retrieve the actual response from the ftp server whenever I send a command (i.e. 'password incorrect', 'access denied', etc. )?

Thanks
 
the answer is, not using the ftp extensions nor by using the PEAR net_ftp alternative. both simply return connect failed (or similar) in the event that a connection fails.

however the net_ftp extension does make use of PEAR::ERROR for other commands and you should find more user friendly error messages there.

another alternative is to use cURL natively.
 
jpadie,

Am I reading this correct that there is no way to get the message using the native php ftp functions (or PEAR for that matter)? Is the only alternative to use fsockopen or socket_connect and send the ftp commands manually?

The problem I run into with that is that if a do an fgets and pass the socket connection resource to it, and for whatever reason the actual connection dropped, it just hangs. It's rare, but it happens. PHP still has a valid resource, even though the actual connection is gone, so is_resource (falsely) returns true. So I dont know of a way of checking to make sure the actual connection is still there.

It's kinda a catch-22, I need to check to see if the connection is established. But in order to do that, I need to pass a valid connection resource.

 
if it's a timeout issue then why not use ftp_set_option to extend the timeout value?
 
The problem is that I don't know if it is a timeout issue or not. All I am saying is that if there is an error, timeout or otherwise, I would like to get the response the server sends back. In other words, if I try to do an ftp_put() for example and it returns false, I want to know why.
 
you're not going to get that information from the built in functions. if i were you i'd bump up the timeout and see whether the issue persists.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top