我试图在网上搜索,但我找不到关于我试图弄清楚的问题的明确观点。
我有一种情况,上传的文件将通过 FTP (Egnyte) 发送到另一台服务器。我有一个本地主机设置,它成功地将文件上传到 FTP,但没有在它给我一个 curl 错误 (25) 的实时站点中 - 在 FTP 中,STOR 命令已被拒绝。它还有一条“FTP 上传失败:451”的错误消息。更让我烦恼的是,服务器已经从实时站点克隆了 staging / dev 并且它在那里完美地工作。
我应该在实时站点的服务器中查看本地主机设置中的哪些内容和/或 curl 错误的可能原因?顺便说一句,在实时服务器中启用了 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 );
}