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 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办