dougou1943 2014-07-10 08:49
浏览 142
已采纳

PHP Curl错误代码25

I tried to search the web but I couldn't find a clear point on the issue I'm trying to figure out.

I have a situation where the uploaded files will be sent over to another server via FTP (Egnyte). I have a localhost setup and it succeeded uploading the files to FTP but not in the live site where it gives me a curl error (25) - in FTP, STOR command has been denied. It has a further error message of "Failed FTP upload: 451". What bugs me even more is, the server has staging / dev cloned from the live site and it perfectly works there.

What could be in the localhost setup that I should look in the server of the live site and/or possible causes of the curl error? Curl is enabled in the live server btw.

My curl options (considering variables are supplied properly and ftp has been connected):

// connection options
    $options = array(
        CURLOPT_USERPWD        => $username . ':' . $password,
        CURLOPT_SSL_VERIFYPEER => false, // don't verify SSL
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_FTP_SSL        => CURLFTPSSL_ALL, // require SSL For both control and data connections
        CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT, // let cURL choose the FTP authentication method (either SSL or TLS)
        CURLOPT_UPLOAD         => true,
        CURLOPT_PORT           => $port,
        CURLOPT_TIMEOUT        => 30,
    );

and here's my upload function:

public function upload( $file_name, $file ) {

    // set file name
    if ( ! curl_setopt( $this->curl_handle, CURLOPT_URL, $this->url . $file_name ))
        throw new Exception ( "Could not set cURL file name: $file_name" );

    /* Open the file for writing  */
    $file_stream = fopen($file, "r");

    /* Open a memory for writing */
    $stream = fopen('php://temp' , "wb");

    /* Read the file and write it to the stream 1kb at a time */
    while ($data = fread($file_stream, 1024))
        fwrite($stream, $data);

    // rewind the stream pointer
    rewind( $stream );

    // set the file to be uploaded
    if ( ! curl_setopt( $this->curl_handle, CURLOPT_INFILE, $stream ) )
        throw new Exception( "Could not load file $file_name" );

    // upload file
    if ( ! curl_exec( $this->curl_handle ) ) {
        throw new Exception( sprintf( 'Could not upload file. cURL Error: [%s] - %s', curl_errno( $this->curl_handle ), curl_error( $this->curl_handle ) ) );
    }

    // close the stream handle
    fclose( $stream );
    fclose( $file_stream );
}
  • 写回答

1条回答 默认 最新

  • douju6651 2014-08-06 13:06
    关注

    I actually figured this issue 2 weeks ago.

    It seems like in the live site, it fails when there are spaces in the filename. For now, replacing the spaces with underscores should be good. Not yet sure though why its perfectly fine to have spaces when I integrated the script in the localhost setup.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。
  • ¥15 已知隐函数其中一个变量τ的具体值,求另一个变量
  • ¥15 r语言Hurst指数
  • ¥15 Acrn IVSHMEM doorbell问题
  • ¥15 yolov5中的val测试集训练时数量变小问题
  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 echarts图表制作