Check FTP status codes using PHP script

I have a script that checks responses from HTTP servers using the PEAR HTTP classes. However, I recently discovered that the script does not work on FTP servers (and probably nothing but HTTP or HTTPS). I tried Google but did not see any scripts or code that returned the server status code from servers other than HTTP servers.

How to find out the status of a newsgroup or FTP server using PHP?

EDIT: I should clarify that I'm only interested in being able to read from the FTP server and the directory that I specify. I need to know if the server is dead or not, I am not authorized to read, etc.

Please note that although in most cases I am agnostic in the language, the whole site is managed by PHP, so the PHP solution will be the best for ease of maintenance and extensibility in the future.

+5
source share
3 answers

HTTP works a little differently than FTP, but unfortunately. Although both options may look the same in your browser, HTTP works based on a URI (for example, to access resource A, you have an identifier that tells you how to access it).

FTP is a very old school server. Even anonymous FTP is a bit hacked because you still provide a username and password, it is simply defined as “anonymous” and your email address.

FTP

  • FTP-

    if (!($ftpfd = ftp_connect($hostname))) { ... }

  • :

    if (!ftp_login($ftpfd, $username, $password)) { ... }

  • , , , , - , . , , ftp_mdtm(), , , ftp_nlist().

+2

PHP FTP *, ? URI , (http:// ftp:// ..), , , . protocal ( !), http.

  • .
0

If you want to read specific answers, you will have to manually open the socket and read / write data.

<?php
$sock = fsockopen($hostname, $port);
?>

Then you will need fput / fread data back and forth.
This will require you to read the FTP protocol.

0
source

All Articles