function export() { if (!KBatchBase::pollingFileExists($this->srcFile)) { throw new kTemporaryException("Source file {$this->srcFile} does not exist"); } $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $engineOptions['passiveMode'] = $this->data->ftpPassiveMode; $engineOptions['createLink'] = $this->data->createLink; if ($this->data instanceof KalturaAmazonS3StorageExportJobData) { $engineOptions['filesAcl'] = $this->data->filesPermissionInS3; $engineOptions['s3Region'] = $this->data->s3Region; } $engine = kFileTransferMgr::getInstance($this->protocol, $engineOptions); try { $keyPairLogin = false; if ($this->protocol == KalturaStorageProfileProtocol::SFTP) { $keyPairLogin = $this->data->serverPrivateKey || $this->data->serverPublicKey; } if ($keyPairLogin) { $privateKeyFile = self::getTempFileWithContent($this->data->serverPrivateKey, 'privateKey'); $publicKeyFile = self::getTempFileWithContent($this->data->serverPublicKey, 'publicKey'); $engine->loginPubKey($this->data->serverUrl, $this->data->serverUsername, $publicKeyFile, $privateKeyFile, $this->data->serverPassPhrase); } else { $engine->login($this->data->serverUrl, $this->data->serverUsername, $this->data->serverPassword); } } catch (Exception $e) { throw new kTemporaryException($e->getMessage()); } try { if (is_file($this->srcFile)) { $engine->putFile($this->destFile, $this->srcFile, $this->data->force); if (KBatchBase::$taskConfig->params->chmod) { try { $engine->chmod($this->destFile, KBatchBase::$taskConfig->params->chmod); } catch (Exception $e) { } } } else { if (is_dir($this->srcFile)) { $filesPaths = kFile::dirList($this->srcFile); $destDir = $this->destFile; foreach ($filesPaths as $filePath) { $destFile = $destDir . '/' . basename($filePath); $engine->putFile($destFile, $filePath, $this->data->force); if (KBatchBase::$taskConfig->params->chmod) { try { $engine->chmod($destFile, KBatchBase::$taskConfig->params->chmod); } catch (Exception $e) { } } } } } } catch (kFileTransferMgrException $e) { if ($e->getCode() == kFileTransferMgrException::remoteFileExists) { throw new kApplicativeException(KalturaBatchJobAppErrors::FILE_ALREADY_EXISTS, $e->getMessage()); } throw new Exception($e->getMessage(), $e->getCode()); } return true; }