The below function used to upload the local file to remote directory.
[php]
/**
* Upload the file in ftp directory
* @param string $localFilePath
* @param string $remoteFilePath .
* @return boolean
*/
public function CopyFileToFtpBucketDir($localFilePath, $remoteFilePath)
{
<strong><em>//Credential are configured in main.php</em></strong>
$ftpSource = Yii::app()->params[‘ftpSource’];
$ftpUserName = Yii::app()->params[‘ftpUserName’];
$ftpPassword = Yii::app()->params[‘ftpPassword’];
<em><strong>// set up basic connection</strong></em>
$connect = ftp_connect($ftpSource);
if (!$connect)
{
Yii::log(‘ftp is not connected’, CLogger::LEVEL_ERROR, ‘some string to identify.’ . strstr(str_replace(‘/’, ‘.’, __DIR__), ‘some string to identify’) . ‘.’ . __METHOD__);
exit;
}
else
{
Yii::log(“Login with username and password”, CLogger::LEVEL_ERROR, ‘some string to identify.’ . strstr(str_replace(‘/’, ‘.’, __DIR__), ‘some string to identify’) . ‘.’ . __METHOD__);
$loginResult = ftp_login($connect, $ftpUserName, $ftpPassword);
<em><strong>// upload a file</strong></em>
if (ftp_put($connect, $remoteFilePath, $localFilePath, FTP_ASCII))
{
Yii::log(“Successfully uploaded $remoteFilePath\n”, CLogger::LEVEL_ERROR, ‘some string to identify.’ . strstr(str_replace(‘/’, ‘.’, __DIR__), ‘some string to identify’) . ‘.’ . __METHOD__);
$return = true;
}
else
{
Yii::log(“There was a problem while uploading $remoteFilePath\n”, CLogger::LEVEL_ERROR, ‘some string to identify.’ . strstr(str_replace(‘/’, ‘.’, __DIR__), ‘some string to identify’) . ‘.’ . __METHOD__);
$return = false;
}
<em><strong>// close the connection</strong></em>
ftp_close($connect);
return $return;
}
}
[/php]