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