Capture CURL FTP out.

Hi,

Before I begin.  Yes I know there is a PHP FTP function library.  I am just exploring this as an alternative....

Examine this function...

       public function getDir()
        {
            $cmd = "list";
            $ret = "";
            $f = fopen("denise.txt", "w+");

            curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, "pwd");
            curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($this->ch, CURLINFO_HEADER_OUT, true);
            //curl_setopt($this->ch, CURLOPT_WRITEFUNCTION, 'self::progress_function');
            curl_setopt($this->ch, CURLOPT_STDERR, $f);
            //curl_setopt($this->ch, CURLOPT_FILE, $this->out);
            //curl_setopt($this->ch, CURLOPT_FTPASCII, 1);

            //curl_setopt($this->ch, CURLOPT_QUOTE, $cmd);

            curl_setopt($this->ch, CURLOPT_UPLOAD, false);

            $this->lastResponse = curl_exec($this->ch);
            fflush($f);
            $cmd = fread($f, 2048);
            print "Read " . $cmd . "\n";

            $cmd = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);

            print "Command " . $cmd . "\n";

            //$cmd = curl_getinfo($this->ch, CURLINFO_HTTP_);
            $cmd = curl_multi_getcontent($this->ch);

            print "Conntent " . $cmd . "\n";
            //$ret[] = curl_multi_info_read($this->ch);
            //print "Return " . $ret . "\n";
            $this->setLastCurlError();
            //Clear out temp curl option.
            curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, null);
            curl_setopt($this->ch, CURLOPT_UPLOAD, null);
            fclose($f);

            return $this->getLastResponse();
        }

1) Change the custom command to LIST and I can pass a result back to the caller.

Dir ----> drwxr-xr-x 1 ftp ftp              0 Apr 29 15:43 Test1
drwxr-xr-x 1 ftp ftp              0 May 23 01:06 Test2


2) use PWD and I get no response from curl_exec.  But if you look in the console window and have CURLOPT_VERBOSE set to true.  You will see this in the console.

> PWD
< 257 "/" is current directory.


I can capture the FTP return code of 257 by calling...  $cmd = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);  see above function.

Any ideas how I can capture the FTP verbose output???  I have tried all sorts of redirection.

And again I KNOW THERE IS A FTP group of functions...

Thanks in Advance

Regards,

Jim


Attachment(s):
CurlFTP.php.zip

Please sign in to leave a comment.