Good day. There is a PHP code that receives a list of files from an FTP server. The code works through a proxy that supports FTP over HTTP mode. Here is the code itself

$proxy_host = "1.1.1.1"; $proxy_port = 8080; $curl = curl_init(); $ftp_url = 'ftp://login:password@ftp:21/dir'; curl_setopt($curl,CURLOPT_TIMEOUT,10); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); curl_setopt($curl,CURLOPT_FTPLISTONLY,1); curl_setopt($curl,CURLOPT_PROXYTYPE,CURLPROXY_HTTP); curl_setopt($curl,CURLOPT_PROXY,$proxy_host); curl_setopt($curl,CURLOPT_PROXYPORT,$proxy_port); curl_setopt($curl,CURLOPT_PROXYUSERPWD,'login_proxy:password_proxy'); curl_setopt($curl,CURLOPT_URL,$ftp_url); curl_setopt($curl,CURLOPT_VERBOSE,FALSE); curl_setopt($curl,CURLOPT_HEADER,0); $content=curl_exec($curl); echo $content; 

The code works fine, but displaying the file list always prefixes the message.
curl 230 OK. Current restricted directory is / curl 230 OK. Current restricted directory is / . This message is present even when I try to download files. That is, the contents of all downloaded files contain this diagnostic message. How to disable the output of this message?

Addition
The CURLOPT_VERBOSE parameter (true, false, absent) does not affect the message in any way. There is a suspicion that it is enabled by default and does not turn off.

More additions
I tried on versions PHP 5.3.13 and 5.6.30 version curl (from phpinfo) 7.24.0 It is important that without a proxy server everything works fine.

  • Try these settings curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_FTP_SSL, CURLFTPSSL_ALL); curl_setopt($curl, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS); curl_setopt($curl, CURLOPT_SSLVERSION, 3); curl_setopt($curl, CURLOPT_FTPPORT,'-'); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_FTP_SSL, CURLFTPSSL_ALL); curl_setopt($curl, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS); curl_setopt($curl, CURLOPT_SSLVERSION, 3); curl_setopt($curl, CURLOPT_FTPPORT,'-'); - Vanya Avchyan
  • @VanyaAvchyan nothing has changed - Alexus
  • @Alexus need information what version of php do you have and what version of cUrl? tried to make a request without a proxy what came in? - programmer403
  • @ programmer403 added to description ... - Alexus
  • one
    @Alexus Well, then everything is clear, it's not about php, but about the proxy server software. (Yes, I mean, you're not looking there) Try searching the proxy server configuration files. may be easier to change the server - programmer403

3 answers 3

 curl 230 OK. Current restricted directory is / 

This message is not displayed from php, but from the proxy program through which you send the request. I do not know what kind of software there might be this 'Pure-FTPd' or something like that. But it looks like he is doing STDOUT before showing what you requested .. and accordingly your curl is already tightening it all up.

You need to look in the direction of how to silence, send to> / dev / null, look at configs, etc.

    Try options CURLOPT_HEADER or CURLINFO_HEADER_OUT (and probably both together) set to false . Here are additional options, rummage through them if it does not help.

    • Thanks for the answer. Tried all 4 options with CURLOPT_HEADER, CURLOPT_HEADER_OUT the result is the same. I reviewed all the possible options in the curl_setopt function. I did not find anything like a problem. - Alexus
    • and CURLOPT_NOBODY ? And other options that may help? Have you looked through all the documentation? - Tymur Valiiev
    • CURLOPT_NOBODY (already tried) doesn't return anything except headers. - Alexus
    • List files from root directory or from / dir - Raz Galstyan

    If you read carefully

    CURLOPT_VERBOSE: TRUE to display detailed information. Writes the output to STDERR or the file specified by CURLOPT_STDERR.

    Since CURLOPT_VERBOSE - FALSE says nothing, and moreover, in your case it does not correspond to a logical continuation, I think that using the CURLOPT_STDERR option will help solve your problem.

    Replace:

     ..... curl_setopt($curl,CURLOPT_VERBOSE,FALSE); ..... 

    On:

    Create a curl.txt file in curl.txt

     ..... $stderr = fopen("curl.txt", "w"); curl_setopt($curl, CURLOPT_VERBOSE, TRUE); curl_setopt($curl, CURLOPT_STDERR, $stderr); ..... 
    • The file displays a lot of additional information, but the line remains. - Alexus