1 (edited by MattF 2007-12-11 14:14)

Topic: Checking ftp availability

Just another quickie. big_smile Is the following a valid, (and safe), way to check if a ftp server is accepting or denying connections?

if (($handle = @fopen('ftp://anonymous:none@'.$uri, 'r')) !== false)
{
        echo 'Success'."\n";
        fclose($handle);
}

Cheers.

Matt

Re: Checking ftp availability

If you've enabled access to other servers for fopen() it might be, otherwise i would try using fsockopen().

Re: Checking ftp availability

Or use the FTP functions.

4

Re: Checking ftp availability

intedinmamma wrote:

If you've enabled access to other servers for fopen() it might be, otherwise i would try using fsockopen().

Aye. Fopen is enabled. The code is only going to be on the local server, so it's not one of those things I'm going to be adding to distributed code and hoping people have it enabled. smile

5 (edited by MattF 2007-12-11 14:13)

Re: Checking ftp availability

elbekko wrote:

Or use the FTP functions.

I'd never realised until you mentioned that there was a ftp function. big_smile It's not compiled by default, is it? Is the fopen method safe/reliable enough, or would I be better recompiling and using ftp, or using the fsockopen function as mentioned above?

The only thing this is being used to do is to check if the ftp server is returning a file available response for a file, so that a message can be given to browsers if the ftp server is not accepting further connections. Some browsers seem to have trouble handling some ftp server responses correctly, so it's just to take any browser deviation out of the equation. smile