0

Web を検索しようとしましたが、理解しようとしている問題の明確なポイントを見つけることができませんでした。

アップロードされたファイルが FTP (Egnyte) 経由で別のサーバーに送信される状況があります。私はローカルホストをセットアップしており、FTP へのファイルのアップロードに成功しましたが、ライブ サイトではカール エラー (25) が発生しませんでした。FTP では、STOR コマンドが拒否されました。さらに、「Failed FTP upload: 451」というエラー メッセージが表示されます。私をさらに悩ませているのは、サーバーにステージング/開発がライブサイトから複製されており、そこで完全に機能することです。

ライブサイトのサーバーで確認する必要があるローカルホストのセットアップには何がありますか、および/またはカールエラーの考えられる原因は何ですか? Curlはライブサーバーで有効になっています。

私のcurlオプション(変数が適切に提供され、ftpが接続されていることを考慮して):

// 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,
    );

ここに私のアップロード機能があります:

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 );
}
4

1 に答える 1

0

私は実際にこの問題を2週間前に考えました。

ライブサイトのようですが、ファイル名にスペースがあると失敗します。今のところ、スペースをアンダースコアに置き換えるのが良いでしょう。スクリプトをローカルホストのセットアップに統合したときに、スペースを入れても問題ない理由はまだわかりません。

于 2014-08-06T13:06:52.380 に答える