note 15848 deleted from function.fsockopen by jimw
| From: | jimw@php.net | Date: | Sat, 08 Dec 2001 21:57:47 +0000 |
| Subject: | note 15848 deleted from function.fsockopen by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22258@lists.php.net to get a copy of this message | ||
<p>For people trying FTP, and other line orientated protocols, remember:</p>
<p>a) The server sends back information, too, and it's worth waiting for this response,
because the command will have been fully processed by that point. (Hence the need for sleep(1) above
- this isn't needed if you read the server's response.) You'll also get the error
messages and codes - these are useful user feedback. Besides all these good reasons, you'll be
using less memory, because you'll be clearing the socket read buffer.<br>
b) Most line orientated protocols have some form of "quit" or "logout" command.
It's best to use these. More generally, it's best to let the server close the socket when
it's good and ready - some protocols "do" things on the quit command, which can
otherwise cause immediate reconnections to fail. (Some POP3 servers do this, for instance. And are
quite within their rights to do so.)<br>
c) A few of these protocols can support "pipelining" - sending a bunch of commands at
once. ESMTP is one of these - it'll tell you after the "EHLO" command. Although some
protocols generally manage to support it on some servers, even if they don't tell you (and
sometimes don't have the means to tell you), it's best not to rely on this. FTP, for
instance, often will manage the USER/PASS sequence all at once, but there's nothing in the
standard to insist on it.<br>
d)Also, read the standards documents (RFCs) on the protocols you're trying to speak. It's
actually much easier than trying to reverse engineer them, although you might find it useful to look
at someone else's implementation for reference as well.<br>
e)If you're trying to do TELNET, or any TELNET based protocol (Such as FTP), then please
remember that TELNET is not a line orientated protocol. FTP clients can, if I remember right, get
away without handling TELNET, except for certain filenames - FTP supports 8-bit filenames these
days, and you'll need to double up the octet FF (also known as IAC) whereever it
appears.</p>
<p>My apologies for berating the obvious.</p>