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

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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题