<p>I have a script that checks responses from HTTP servers using the PEAR HTTP classes. However, I've recently found that the script fails on FTP servers (and probably anything that's not HTTP or HTTPS). I tried Google, but didn't see any scripts or code that returned the server status code from servers other than HTTP servers.</p>

<p>How can I find out the status of a newsgroup or FTP server using PHP?</p>

<p>EDIT: I should clarify that I am interested only in the ability to read from an FTP server and the directory that I specify. I need to know if the server is dead/gone, I'm not authorized to read, etc.</p>

<p>Please note that, although most of the time I'm language agnostic, the entire website is PHP-driven, so a PHP solution would be the best for easy of maintainability and extensibility in the future.</p>

[{'answer_id': 8740, 'author': 'ZombieSheep', 'author_id': 377, 'author_profile': 'https://Stackoverflow.com/users/377', 'pm_score': 0, 'selected': False, 'text': '<p>Wouldn\'t it be simpler to use the built-in PHP FTP* functionality than trying to roll your own?  If the URI is coming from a source outside your control, you would need to check the protocal definition (http:// or ftp://, etc) in order to determine which functionality to use, but that is fairly trivial.  If there is now protocal specified (there really should be!) then you could try to default to http.</p>\n\n<ul>\n<li>see <a href="http://uk.php.net/ftp" rel="nofollow noreferrer">here</a></li>\n</ul>\n'}, {'answer_id': 8794, 'author': 'Philip Reynolds', 'author_id': 1087, 'author_profile': 'https://Stackoverflow.com/users/1087', 'pm_score': 3, 'selected': True, 'text': '<p>HTTP works slightly differently than FTP though unfortunately. Although both may look the same in your browser, HTTP works off the basis of URI (i.e. to access resource A, you have an identifier which tells you how to access that).</p>\n\n<p>FTP is very old school server driven. Even anonymous FTP is a bit of a hack, since you still supply a username and password, it\'s just defined as "anonymous" and your email address.</p>\n\n<p>Checking if an FTP server is up means checking</p>\n\n<ol>\n<li><p>That you can connect to the FTP server</p>\n\n<p><code>if (!($ftpfd = ftp_connect($hostname))) { ... }</code></p></li>\n<li><p>That you can login to the server:</p>\n\n<p><code>if (!ftp_login($ftpfd, $username, $password)) { ... }</code></p></li>\n<li><p>Then, if there are further underlying resources that you need to access to test whether a particular site is up, then use an appropiate operation on them. e.g. on a file, maybe use <code>ftp_mdtm()</code> to get the last modified time or on a directory, see if <code>ftp_nlist()</code> works.</p></li>\n</ol>\n'}, {'answer_id': 9082, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 0, 'selected': False, 'text': "<p>If you want to read specific responses you will have to open a socket and read/write data manually.</p>\n\n<pre><code>&lt;?php\n$sock = fsockopen($hostname, $port);\n?&gt;\n</code></pre>\n\n<p>Then you'll have to fput/fread data back and forth.<br />\nThis will require you to read up on the FTP protocol.</p>\n"}]
['https://Stackoverflow.com/questions/8726', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/572/']