public function getLocalFilePath($fileName, $fileId, kFileTransferMgr $fileTransferMgr) { $dropFolderFilePath = $this->getPath() . '/' . $fileName; $tempDirectory = sys_get_temp_dir(); if (is_dir($tempDirectory)) { $tempFilePath = tempnam($tempDirectory, 'parse_dropFolderFileId_' . $fileId . '_'); $fileTransferMgr->getFile($dropFolderFilePath, $tempFilePath); return $tempFilePath; } else { KalturaLog::err('Missing temporary directory'); return null; } }
/** * @param KalturaDistributionJobData $data * @param KalturaGenericDistributionProfile $distributionProfile * @param KalturaGenericDistributionJobProviderData $providerData * @throws Exception * @throws kFileTransferMgrException * @return boolean true if finished, false if will be finished asynchronously */ protected function handleAction(KalturaDistributionJobData $data, KalturaGenericDistributionProfile $distributionProfile, KalturaGenericDistributionProfileAction $distributionProfileAction, KalturaGenericDistributionJobProviderData $providerData) { if (!$providerData->xml) { throw new Exception("XML data not supplied"); } $fileName = uniqid() . '.xml'; $srcFile = $this->tempXmlPath . '/' . $fileName; $destFile = $distributionProfileAction->serverPath; if ($distributionProfileAction->protocol != KalturaDistributionProtocol::HTTP && $distributionProfileAction->protocol != KalturaDistributionProtocol::HTTPS) { $destFile .= '/' . $fileName; } $destFile = str_replace('{REMOTE_ID}', $data->remoteId, $destFile); file_put_contents($srcFile, $providerData->xml); KalturaLog::log("XML written to file [{$srcFile}]"); $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $engineOptions['passiveMode'] = $distributionProfileAction->ftpPassiveMode; $engineOptions['fieldName'] = $distributionProfileAction->httpFieldName; $engineOptions['fileName'] = $distributionProfileAction->httpFileName; $fileTransferMgr = kFileTransferMgr::getInstance($distributionProfileAction->protocol, $engineOptions); if (!$fileTransferMgr) { throw new Exception("File transfer manager type [{$distributionProfileAction->protocol}] not supported"); } $fileTransferMgr->login($distributionProfileAction->serverUrl, $distributionProfileAction->username, $distributionProfileAction->password); $fileTransferMgr->putFile($destFile, $srcFile, true); $results = $fileTransferMgr->getResults(); if ($results && is_string($results)) { $data->results = $results; $parsedValues = $this->parseResults($results, $providerData->resultParserType, $providerData->resultParseData); if (count($parsedValues)) { list($data->remoteId) = $parsedValues; } } $data->sentData = $providerData->xml; return true; }
/** * Instances of this class should be created usign the 'getInstance' of the 'kFileTransferMgr' class * Supported options: * - useCmd - indicates that sftp CLI should be used for GET and PUT actions. * - cmdPutMinimumFileSize - CLI will be used for PUT aactions on files larger than this option. * * @param array $options */ protected function __construct(array $options = null) { if (!function_exists('ssh2_connect')) { throw new kFileTransferMgrException("SSH2 extension is not installed.", kFileTransferMgrException::extensionMissing); } if (!function_exists('ssh2_sftp')) { throw new kFileTransferMgrException("SSH2 SFTP extension is not installed.", kFileTransferMgrException::extensionMissing); } parent::__construct($options); $this->tmpDir = sys_get_temp_dir(); if ($options) { if (isset($options['useCmd'])) { $this->useCmd = $options['useCmd']; } if (isset($options['sftpCmd'])) { $this->sftpCmd = $options['sftpCmd']; } if (isset($options['sshpassCmd'])) { $this->sshpassCmd = $options['sshpassCmd']; } if (isset($options['useCmdChmod'])) { $this->useCmdChmod = $options['useCmdChmod']; } if (isset($options['cmdPutMinimumFileSize'])) { $this->cmdPutMinimumFileSize = $options['cmdPutMinimumFileSize']; } if (isset($options['tmpDir'])) { $this->tmpDir = $options['tmpDir']; } } }
protected function __construct(array $options = null) { if (!function_exists('ssh2_connect')) { throw new kFileTransferMgrException("SSH2 extension is not installed.", kFileTransferMgrException::extensionMissing); } parent::__construct($options); }
/** * * Physically delete the file in $sharedPhysicalFilePath and change the $dropFolderFile status to KalturaDropFolderFileStatus::PURGED * @param KalturaDropFolderFile $dropFolderFile * @param string $sharedPhysicalFilePath */ private function purgeFile(KalturaDropFolderFile $dropFolderFile, $physicalFilePath) { // physicaly delete the file $delResult = null; try { $delResult = $this->fileTransferMgr->delFile($physicalFilePath); } catch (Exception $e) { $this->unimpersonate(); KalturaLog::err('Cannot delete physical file [' . $physicalFilePath . '] for drop folder file id [' . $dropFolderFile->id . '] - ' . $e->getMessage()); return false; } if (!$delResult) { KalturaLog::err("Cannot delete physical file at path [{$physicalFilePath}]"); try { $this->impersonate($dropFolderFile->partnerId); $this->dropFolderPlugin->dropFolderFile->updateStatus($dropFolderFile->id, KalturaDropFolderFileStatus::ERROR_DELETING); $this->unimpersonate(); } catch (Exception $e) { $this->unimpersonate(); KalturaLog::err('Cannot update status for drop folder file id [' . $dropFolderFile->id . '] - ' . $e->getMessage()); } return false; } // change status to PURGED return $this->setFileAsPurged($dropFolderFile); }
protected function getSFTPManager(KalturaFreewheelDistributionProfile $distributionProfile) { $loginName = $distributionProfile->sftpLogin; $loginPass = $distributionProfile->sftpPass; $sftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP); $sftpManager->login(self::FREEWHEEL_SFTP_SERVER, $loginName, $loginPass); return $sftpManager; }
protected function getSFTPManager(KalturaFreewheelDistributionProfile $distributionProfile) { $loginName = $distributionProfile->sftpLogin; $loginPass = $distributionProfile->sftpPass; $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $sftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP, $engineOptions); $sftpManager->login(self::FREEWHEEL_SFTP_SERVER, $loginName, $loginPass); return $sftpManager; }
protected function __construct(array $options = null) { parent::__construct($options); if ($options) { if (isset($options['createLink'])) { $this->createLink = $options['createLink']; } } }
protected function __construct(array $options = null) { parent::__construct($options); if (!$options || !isset($options['asperaTempFolder'])) { throw new kFileTransferMgrException("Option attribute [asperaTempFolder] is missing.", kFileTransferMgrException::attributeMissing); } $this->asperaTempFolder = $options['asperaTempFolder']; if (isset($options['ascpCmd'])) { $this->ascpCmd = $options['ascpCmd']; } }
/** * Init a kFileTransferManager acccording to folder type and login to the server * @param KalturaDropFolder $folder * @throws Exception * * @return kFileTransferMgr */ public static function getFileTransferManager(KalturaDropFolder $folder) { $fileTransferMgr = null; $host = $port = $username = $password = $privateKey = $publicKey = $passPhrase = null; switch ($folder->type) { case KalturaDropFolderType::LOCAL: $fileTransferMgr = kFileTransferMgr::getInstance(kFileTransferMgrType::LOCAL); $host = $port = $username = $password = true; break; case KalturaDropFolderType::FTP: $fileTransferMgr = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP); $host = $folder->host; $port = $folder->port; $username = $folder->username; $password = $folder->password; break; case KalturaDropFolderType::SFTP: $fileTransferMgr = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP); $host = $folder->host; $port = $folder->port; $username = $folder->username; $password = $folder->password; $privateKey = isset($folder->privateKey) ? $folder->privateKey : null; $publicKey = isset($folder->publicKey) ? $folder->publicKey : null; $passPhrase = isset($folder->passPhrase) ? $folder->passPhrase : null; break; case KalturaDropFolderType::SCP: $fileTransferMgr = kFileTransferMgr::getInstance(kFileTransferMgrType::SCP); $host = $folder->host; $port = $folder->port; $username = $folder->username; $password = $folder->password; $privateKey = isset($folder->privateKey) ? $folder->privateKey : null; $publicKey = isset($folder->publicKey) ? $folder->publicKey : null; $passPhrase = isset($folder->passPhrase) ? $folder->passPhrase : null; break; default: throw new Exception('Unsupported drop folder type [' . $folder->type . ']'); } try { // login to server if (!$privateKey || !$publicKey) { $fileTransferMgr->login($host, $username, $password, $port); } else { $privateKeyFile = self::getTempFileWithContent($privateKey, 'privateKey'); $publicKeyFile = self::getTempFileWithContent($publicKey, 'publicKey'); $fileTransferMgr->loginPubKey($host, $username, $publicKeyFile, $privateKeyFile, $passPhrase, $port); } } catch (Exception $e) { throw $e; } return $fileTransferMgr; }
private function getLocalXmlFilePath() { $dropFolderFilePath = $this->dropFolder->path . '/' . $this->dropFolderFile->fileName; // local drop folder if ($this->dropFolder->type == KalturaDropFolderType::LOCAL) { $dropFolderFilePath = realpath($dropFolderFilePath); return $dropFolderFilePath; } // remote drop folder $tempFilePath = tempnam($this->tempDirectory, 'dropFolderFileId_' . $this->dropFolderFile->id . '_'); $this->fileTransferMgr->getFile($dropFolderFilePath, $tempFilePath); return $tempFilePath; }
protected function __construct(array $options = null) { parent::__construct($options); if ($options && isset($options['filesAcl'])) { $this->filesAcl = $options['filesAcl']; } if ($options && isset($options['s3Region'])) { $this->s3Region = $options['s3Region']; } // do nothing $this->connection_id = 1; //SIMULATING! }
/** * Local drop folder - constract full path * Remote drop folder - download file to a local temp directory and return the temp file path * @param string $fileName * @param int $fileId * @throws Exception */ protected function getLocalFilePath($fileName, $fileId) { $dropFolderFilePath = $this->dropFolder->path . '/' . $fileName; // local drop folder if ($this->dropFolder->type == KalturaDropFolderType::LOCAL) { $dropFolderFilePath = realpath($dropFolderFilePath); return $dropFolderFilePath; } else { // remote drop folder $tempFilePath = tempnam(KBatchBase::$taskConfig->params->sharedTempPath, 'parse_dropFolderFileId_' . $fileId . '_'); $this->fileTransferMgr->getFile($dropFolderFilePath, $tempFilePath); $this->setFilePermissions($tempFilePath); return $tempFilePath; } }
protected function __construct(array $options = null) { parent::__construct($options); if ($options) { if (isset($options['userAgent'])) { $this->userAgent = $options['userAgent']; } if (isset($options['fieldName'])) { $this->fieldName = $options['fieldName']; } if (isset($options['fileName'])) { $this->fileName = $options['fileName']; } } }
/** * Will take a single KalturaBatchJob and delete the given file * * @param KalturaBatchJob $job * @param KalturaStorageDeleteJobData $data * @return KalturaBatchJob */ private function delete(KalturaBatchJob $job, KalturaStorageDeleteJobData $data) { KalturaLog::debug("delete({$job->id})"); $srcFile = str_replace('//', '/', trim($data->srcFileSyncLocalPath)); $destFile = str_replace('//', '/', trim($data->destFileSyncStoredPath)); $this->updateJob($job, "Deleteing {$srcFile} to {$destFile}", KalturaBatchJobStatus::QUEUED, 1); $engine = kFileTransferMgr::getInstance($job->jobSubType); try { $engine->login($data->serverUrl, $data->serverUsername, $data->serverPassword, null, $data->ftpPassiveMode); $engine->delFile($srcFile); } catch (kFileTransferMgrException $ke) { return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, $ke->getCode(), $ke->getMessage(), KalturaBatchJobStatus::FAILED); } catch (Exception $e) { return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $e->getCode(), $e->getMessage(), KalturaBatchJobStatus::FAILED); } return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::FINISHED); }
protected function __construct(array $options = null) { if (!function_exists('ftp_connect')) { throw new kFileTransferMgrException("FTP extension is not installed.", kFileTransferMgrException::extensionMissing); } parent::__construct($options); if ($options) { if (isset($options['mode'])) { $this->mode = $options['mode']; } if (isset($options['passiveMode'])) { $this->passiveMode = $options['passiveMode']; } } if ($this->mode != FTP_ASCII) { $this->mode = FTP_BINARY; } }
/** * Will take a single KalturaBatchJob and export the given file * * @param KalturaBatchJob $job * @param KalturaStorageExportJobData $data * @return KalturaBatchJob */ protected function export(KalturaBatchJob $job, KalturaStorageExportJobData $data) { KalturaLog::debug("export({$job->id})"); $srcFile = str_replace('//', '/', trim($data->srcFileSyncLocalPath)); if (!$this->pollingFileExists($srcFile)) { return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, "Source file {$srcFile} does not exist", KalturaBatchJobStatus::RETRY); } $destFile = str_replace('//', '/', trim($data->destFileSyncStoredPath)); $this->updateJob($job, "Exporting {$srcFile} to {$destFile}", KalturaBatchJobStatus::QUEUED, 1); $engine = kFileTransferMgr::getInstance($job->jobSubType); try { $engine->login($data->serverUrl, $data->serverUsername, $data->serverPassword, null, $data->ftpPassiveMode); } catch (Exception $e) { return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $e->getCode(), $e->getMessage(), KalturaBatchJobStatus::RETRY); } try { if (is_file($srcFile)) { $engine->putFile($destFile, $srcFile, $data->force); } else { if (is_dir($srcFile)) { $filesPaths = kFile::dirList($srcFile); $destDir = $destFile; foreach ($filesPaths as $filePath) { $destFile = $destDir . DIRECTORY_SEPARATOR . basename($filePath); $engine->putFile($destFile, $filePath, $data->force); } } } } catch (kFileTransferMgrException $e) { if ($e->getCode() == kFileTransferMgrException::remoteFileExists) { return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::FILE_ALREADY_EXISTS, $e->getMessage(), KalturaBatchJobStatus::FAILED); } return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $e->getCode(), $e->getMessage(), KalturaBatchJobStatus::FAILED); } catch (Exception $e) { return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $e->getCode(), $e->getMessage(), KalturaBatchJobStatus::FAILED); } if ($this->taskConfig->params->chmod) { try { $engine->chmod($destFile, $this->taskConfig->params->chmod); } catch (Exception $e) { } } return $this->closeJob($job, null, null, null, KalturaBatchJobStatus::FINISHED); }
protected function getDropFolderFilesFromPhysicalFolder() { if ($this->fileTransferMgr->fileExists($this->dropFolder->path)) { $physicalFiles = $this->fileTransferMgr->listFileObjects($this->dropFolder->path); if ($physicalFiles) { KalturaLog::log('Found [' . count($physicalFiles) . '] in the folder'); } else { KalturaLog::info('No physical files found for drop folder id [' . $this->dropFolder->id . '] with path [' . $this->dropFolder->path . ']'); $physicalFiles = array(); } } else { throw new kFileTransferMgrException('Drop folder path not valid [' . $this->dropFolder->path . ']', kFileTransferMgrException::remotePathNotValid); } KalturaLog::info("physical files: "); foreach ($physicalFiles as &$currlFile) { KalturaLog::info(print_r($currlFile, true)); } return $physicalFiles; }
/** * * @param KalturaFtpDistributionProfile $distributionProfile * @return kFileTransferMgr */ protected function getFileTransferManager(KalturaFtpDistributionProfile $distributionProfile) { $host = $distributionProfile->host; $port = $distributionProfile->port; $protocol = $distributionProfile->protocol; $username = $distributionProfile->username; $password = $distributionProfile->password; if ($protocol == KalturaDistributionProtocol::ASPERA) { $publicKey = $distributionProfile->asperaPublicKey; $privateKey = $distributionProfile->asperaPrivateKey; } else { $publicKey = $distributionProfile->sftpPublicKey; $privateKey = $distributionProfile->sftpPrivateKey; } $passphrase = $distributionProfile->passphrase ? $distributionProfile->passphrase : null; $fileTransferManager = kFileTransferMgr::getInstance($protocol); if (trim($privateKey)) { try { $publicKeyTempPath = $this->getFileLocationForSFTPKey($distributionProfile->id, $publicKey, 'publickey'); $privateKeyTempPath = $this->getFileLocationForSFTPKey($distributionProfile->id, $privateKey, 'privatekey'); $fileTransferManager->loginPubKey($host, $username, $publicKeyTempPath, $privateKeyTempPath, $passphrase, $port ? $port : null); } catch (Exception $ex) { if (file_exists($publicKeyTempPath)) { unlink($publicKeyTempPath); } if (file_exists($privateKeyTempPath)) { unlink($privateKeyTempPath); } throw $ex; } } else { $fileTransferManager->login($host, $username, $password, $port ? $port : null); } return $fileTransferManager; }
/** * * @param KalturaYouTubeDistributionProfile $distributionProfile * @return sftpMgr */ protected function getSFTPManager(KalturaYouTubeDistributionProfile $distributionProfile) { $serverUrl = $distributionProfile->sftpHost; $loginName = $distributionProfile->sftpLogin; $publicKeyFile = $this->getFileLocationForSFTPKey($distributionProfile->id, $distributionProfile->sftpPublicKey, 'publickey'); $privateKeyFile = $this->getFileLocationForSFTPKey($distributionProfile->id, $distributionProfile->sftpPrivateKey, 'privatekey'); $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $sftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP, $engineOptions); $sftpManager->loginPubKey($serverUrl, $loginName, $publicKeyFile, $privateKeyFile); return $sftpManager; }
private function fetchFileSsh(KalturaBatchJob $job, KalturaSshImportJobData $data) { KalturaLog::debug("fetchFile({$job->id})"); try { $sourceUrl = $data->srcFileUrl; KalturaLog::debug("sourceUrl [{$sourceUrl}]"); // extract information from URL and job data $parsedUrl = parse_url($sourceUrl); $host = isset($parsedUrl['host']) ? $parsedUrl['host'] : null; $remotePath = isset($parsedUrl['path']) ? $parsedUrl['path'] : null; $username = isset($parsedUrl['user']) ? $parsedUrl['user'] : null; $password = isset($parsedUrl['pass']) ? $parsedUrl['pass'] : null; $privateKey = isset($data->privateKey) ? $data->privateKey : null; $publicKey = isset($data->publicKey) ? $data->publicKey : null; $passPhrase = isset($data->passPhrase) ? $data->passPhrase : null; KalturaLog::debug("host [{$host}] remotePath [{$remotePath}] username [{$username}] password [{$password}]"); if ($privateKey || $publicKey) { KalturaLog::debug("Private Key: {$privateKey}"); KalturaLog::debug("Public Key: {$publicKey}"); } if (!$host) { $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::MISSING_PARAMETERS, 'Error: missing host', KalturaBatchJobStatus::FAILED); return $job; } if (!$remotePath) { $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::MISSING_PARAMETERS, 'Error: missing host', KalturaBatchJobStatus::FAILED); return $job; } // create suitable file transfer manager object $subType = $job->jobSubType; $fileTransferMgr = kFileTransferMgr::getInstance($subType); if (!$fileTransferMgr) { $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::ENGINE_NOT_FOUND, "Error: file transfer manager not found for type [{$subType}]", KalturaBatchJobStatus::FAILED); return $job; } // login to server if (!$privateKey || !$publicKey) { $fileTransferMgr->login($host, $username, $password); } else { $privateKeyFile = $this->getFileLocationForSshKey($privateKey, 'privateKey'); $publicKeyFile = $this->getFileLocationForSshKey($publicKey, 'publicKey'); $fileTransferMgr->loginPubKey($host, $username, $publicKeyFile, $privateKeyFile, $passPhrase); } // check if file exists $fileExists = $fileTransferMgr->fileExists($remotePath); if (!$fileExists) { $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::MISSING_PARAMETERS, "Error: remote file [{$remotePath}] does not exist", KalturaBatchJobStatus::FAILED); return $job; } // get file size $fileSize = $fileTransferMgr->fileSize($remotePath); // create a temp file path $destFile = $this->getTempFilePath($remotePath); $data->destFileLocalPath = $destFile; KalturaLog::debug("destFile [{$destFile}]"); // download file - overwrite local if exists $this->updateJob($job, "Downloading file, size: {$fileSize}", KalturaBatchJobStatus::PROCESSING, 2, $data); KalturaLog::debug("Downloading remote file [{$remotePath}] to local path [{$destFile}]"); $res = $fileTransferMgr->getFile($remotePath, $destFile); if (!file_exists($data->destFileLocalPath)) { $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::OUTPUT_FILE_DOESNT_EXIST, "Error: output file doesn't exist", KalturaBatchJobStatus::RETRY); return $job; } // check the file size only if its first or second retry // in case it failed few times, taks the file as is if ($fileSize) { clearstatcache(); $actualFileSize = kFile::fileSize($data->destFileLocalPath); if ($actualFileSize < $fileSize) { $percent = floor($actualFileSize * 100 / $fileSize); $job = $this->updateJob($job, "Downloaded size: {$actualFileSize}({$percent}%)", KalturaBatchJobStatus::PROCESSING, $percent, $data); $this->kClient->batch->resetJobExecutionAttempts($job->id, $this->getExclusiveLockKey(), $job->jobType); return $job; } } $this->updateJob($job, 'File imported, copy to shared folder', KalturaBatchJobStatus::PROCESSED, 90); $job = $this->moveFile($job, $data->destFileLocalPath, $fileSize); } catch (Exception $ex) { $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ex->getCode(), "Error: " . $ex->getMessage(), KalturaBatchJobStatus::FAILED); } return $job; }
/** * * @param KalturaYouTubeDistributionProfile $distributionProfile * @return sftpMgr */ protected function getSFTPManager(KalturaYouTubeDistributionProfile $distributionProfile) { $serverUrl = $distributionProfile->sftpHost; $loginName = $distributionProfile->sftpLogin; $publicKeyFile = $this->getFileLocationForSFTPKey($distributionProfile->id, $distributionProfile->sftpPublicKey, 'publickey'); $privateKeyFile = $this->getFileLocationForSFTPKey($distributionProfile->id, $distributionProfile->sftpPrivateKey, 'privatekey'); $sftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP); $sftpManager->loginPubKey($serverUrl, $loginName, $publicKeyFile, $privateKeyFile); return $sftpManager; }
/** * @param KalturaDistributionJobData $data * @param KalturaExampleDistributionProfile $distributionProfile * @param KalturaExampleDistributionJobProviderData $providerData */ protected function handleUpdate(KalturaDistributionJobData $data, KalturaExampleDistributionProfile $distributionProfile, KalturaExampleDistributionJobProviderData $providerData) { $entryId = $data->entryDistribution->entryId; $partnerId = $distributionProfile->partnerId; $entry = $this->getEntry($partnerId, $entryId); $feed = new KDOMDocument(); $feed->load($this->updateXmlTemplate); $feed->documentElement->setAttribute('mediaId', $data->remoteId); $nodes = array('title' => 'name', 'description' => 'description', 'width' => 'width', 'height' => 'height'); foreach ($nodes as $nodeName => $entryAttribute) { $nodeElements = $feed->getElementsByTagName($nodeName); foreach ($nodeElements as $nodeElement) { $nodeElement->textContent = $entry->{$entryAttribute}; } } // get the first asset id $thumbAssetIds = explode(',', $data->entryDistribution->thumbAssetIds); $thumbAssetId = reset($thumbAssetIds); $thumbElements = $feed->getElementsByTagName('thumb'); $thumbElement = reset($thumbElements); $thumbElement->textContent = $this->getThumbAssetUrl($thumbAssetId); $videosElements = $feed->getElementsByTagName('videos'); $videosElement = reset($videosElements); $flavorAssets = $this->getFlavorAssets($partnerId, $data->entryDistribution->flavorAssetIds); KBatchBase::impersonate($partnerId); foreach ($flavorAssets as $flavorAsset) { $url = $this->getFlavorAssetUrl($flavorAsset->id); $videoElement = $feed->createElement('video'); $videoElement->textContent = $url; $videosElement->appendChild($videoElement); } KBatchBase::unimpersonate(); $localFile = tempnam(sys_get_temp_dir(), 'example-update-'); $feed->save($localFile); // loads ftp manager $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $ftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP, $engineOptions); $ftpManager->login(self::FTP_SERVER_URL, $distributionProfile->username, $distributionProfile->password); // put the XML file on the FTP $remoteFile = $entryId . '.xml'; $ftpManager->putFile($remoteFile, $localFile); return true; }
/** * * @param KalturaAttUverseDistributionProfile $distributionProfile * @return ftpMgr */ protected function getFTPManager(KalturaAttUverseDistributionProfile $distributionProfile) { $host = $distributionProfile->ftpHost; $login = $distributionProfile->ftpUsername; $password = $distributionProfile->ftpPassword; $ftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP); $ftpManager->login($host, $login, $password); return $ftpManager; }
/** * * @param KalturaHuluDistributionProfile $distributionProfile * @return sftpMgr */ protected function getSFTPManager(KalturaHuluDistributionProfile $distributionProfile) { $serverUrl = $distributionProfile->sftpHost; $loginName = $distributionProfile->sftpLogin; $loginPass = $distributionProfile->sftpPass; $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $sftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP, $engineOptions); $sftpManager->login($serverUrl, $loginName, $loginPass); return $sftpManager; }
/** * * @param KalturaQuickPlayDistributionProfile $distributionProfile * @return sftpMgr */ protected function getSFTPManager(KalturaQuickPlayDistributionProfile $distributionProfile) { $host = $distributionProfile->sftpHost; $login = $distributionProfile->sftpLogin; $pass = $distributionProfile->sftpPass; $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $sftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP, $engineOptions); $sftpManager->login($host, $login, $pass); return $sftpManager; }
/** * @param KalturaMetroPcsDistributionProfile $distributionProfile */ protected function fetchFilesList(KalturaMetroPcsDistributionProfile $distributionProfile) { $host = $distributionProfile->ftpHost; $login = $distributionProfile->ftpLogin; $pass = $distributionProfile->ftpPass; $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $fileTransferMgr = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP, $engineOptions); if (!$fileTransferMgr) { throw new Exception("FTP manager not loaded"); } $fileTransferMgr->login($host, $host, $pass); return $fileTransferMgr->listDir('/'); }
/** * * @param KalturaHuluDistributionProfile $distributionProfile * @return sftpMgr */ protected function getSFTPManager(KalturaHuluDistributionProfile $distributionProfile) { $serverUrl = $distributionProfile->sftpHost; $loginName = $distributionProfile->sftpLogin; $loginPass = $distributionProfile->sftpPass; $sftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP_CMD); $sftpManager->login($serverUrl, $loginName, $loginPass); return $sftpManager; }
/** * * @param KalturaYouTubeDistributionProfile $distributionProfile * @return sftpMgr */ protected function getSFTPManager(KalturaYouTubeDistributionProfile $distributionProfile) { if (!is_null($this->_sftpManager)) { return $this->_sftpManager; } $serverUrl = $distributionProfile->sftpHost; $loginName = $distributionProfile->sftpLogin; $publicKeyFile = $this->getFileLocationForSFTPKey($distributionProfile->id, $distributionProfile->sftpPublicKey, 'publickey'); $privateKeyFile = $this->getFileLocationForSFTPKey($distributionProfile->id, $distributionProfile->sftpPrivateKey, 'privatekey'); $port = 22; if ($distributionProfile->sftpPort) { $port = $distributionProfile->sftpPort; } $sftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP_CMD); $sftpManager->loginPubKey($serverUrl, $loginName, $publicKeyFile, $privateKeyFile, null, $port); $this->_sftpManager = $sftpManager; return $this->_sftpManager; }
print_r(preg_split("/\\./", $matches[0])); } else { echo 'non'; } return; if (isset($argv[1])) { $entryId = $argv[1]; } foreach ($argv as $arg) { $matches = null; if (preg_match('/(.*)=(.*)/', $arg, $matches)) { $field = $matches[1]; // $providerData->$field = $matches[2]; } } $fileTransferMgr = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP); if (!$fileTransferMgr) { throw new Exception("SFTP manager not loaded"); } $fileTransferMgr->login('ftp-int.vzw.real.com', 'vp_foxsports', 'X4ul3ap'); print_r($fileTransferMgr->listDir("/pub/in")); // $fileTransferMgr->putFile($destFile, $srcFile, true); return; $entry = entryPeer::retrieveByPKNoFilter($entryId); $mrss = kMrssManager::getEntryMrss($entry); file_put_contents('mrss.xml', $mrss); KalturaLog::debug("MRSS [{$mrss}]"); $distributionJobData = new KalturaDistributionSubmitJobData(); $dbDistributionProfile = DistributionProfilePeer::retrieveByPK(2); $distributionProfile = new KalturaYoutubeApiDistributionProfile(); $distributionProfile->fromObject($dbDistributionProfile);