Firstly I would like to say that this is NOT a request for help, but
rather the answer I found to the question I had asked more then a week
ago, but got no response.  From the lack of response I would assume that
a) nobody cared that I had a problem, or b) that nobody knew the
answer... I hope there were many less a)'s then b)'s but I thank
everyone who did take the time to at least read my request for help. I'm
posting what i found for the people who do their best to help, but don't
always know all of the answers (hey, who does?!)

My problem was with accessing the information awaiting me in sockets

heres the quick and dirty (the rest is after the code)


        function display($data) {
                // used to echo our results...
                echo '<hr><pre>';
                if ( is_array($data) ) {
                        // make sure the data is real ;)
                        foreach ( $data as $idx => $val ) {
                                echo ':'.$idx.': '.$val;
                echo '</pre><hr>';

        function return_buffer($fp) {
                // get all the data from the socket buffer
                while ( $data = fgets($fp, 9999) ) {

        // lets START establishing a connection to an FTP site...

        $pass='[EMAIL PROTECTED]';

        // actually initiate the connection
        $fp=fsockopen($host, $port, $est, $eno);
        socket_set_blocking($fp, 1);    // make fgets() wait for data
        socket_set_timeout($fp, 1, 0);  // set fgets() timeout delay


        // send username
        fputs($fp, 'user '.$user.chr(10));
        // get response

        // send password
        fputs($fp, 'pass '.$pass.chr(10));
        // get response

        // log off
        fputs($fp, 'quit'.chr(10).'bye'.chr(10));
        // get response (usually nothing)

        // close the socket (if it's still open)

        // echo our data


The above code DOES work, to some extent... ONLY the banner will be
received and echoed.... after much research, and brute force testing i
found that php keeps the timeout status on the socket.  which causes all
subsequent fgets() functions to do nothing at all (basically php
considerer's the socket to be at its EOF)  you can remedy this by
placing another "socket_set_timeout($fp, 1, 0);" in the script, but just
after the while loop in the return_buffer function... this will reset
the timeout status on the socket each time it's read from... the
resulting function (coded below) will allow the script to do precisely
as it was intended to do... log in, get all the data associated with
logging in, and then logging out...

        function return_buffer($fp) {
                // get all the data from the socket buffer
                while ( $data = fgets($fp, 9999) ) {
                socket_set_timeout($fp, 1, 0);

Thanks again, and Cheers!
Replies, comments, concerns welcome

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to