/** * @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; }
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; }
/** * 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; }
/** * 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); }
/** * 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); }
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);
/** * * @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 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; }
/** * 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 (!file_exists($srcFile)) { return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, "Source file {$srcFile} does not exist", KalturaBatchJobStatus::RETRY); } if (!is_file($srcFile)) { return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, "Source file {$srcFile} is not a file", KalturaBatchJobStatus::FAILED); } $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); $engine->putFile($destFile, $srcFile, $data->force); } catch (kFileTransferMgrException $ke) { return $this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ke->getCode(), $ke->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); }
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; }
/** * Prepares the environment before running a test. */ protected function setUp() { parent::setUp(); $testConfig = $this->config->get('config'); $this->kFileTransferMgr = kFileTransferMgr::getInstance($testConfig->managerType); }
$port = isset($parsedUrl['port']) ? $parsedUrl['port'] : null; $username = isset($parsedUrl['user']) ? $parsedUrl['user'] : null; $password = isset($parsedUrl['pass']) ? $parsedUrl['pass'] : null; $privateKey = null; $publicKey = null; if ($jobData instanceof kSshImportJobData) { $privateKey = $jobData->getPrivateKey() ? $jobData->getPrivateKey() : null; $publicKey = $jobData->getPublicKey() ? $jobData->getPublicKey() : null; $passPhrase = $jobData->getPassPhrase() ? $jobData->getPassPhrase() : null; } KalturaLog::debug("Import Batch Job [{$batchJobPartnerId}::{$batchJobId}] host [{$host}] port [{$port}] remotePath [{$remotePath}] username [{$username}] password [{$password}]"); if ($privateKey || $publicKey) { KalturaLog::debug("Private Key: {$privateKey}"); KalturaLog::debug("Public Key: {$publicKey}"); } $sftp = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP_SEC_LIB); $publicKeyFile = uniqid('sftp-pub-'); $privateKeyFile = uniqid('sftp-pvt-'); try { if (!$privateKey || !$publicKey) { $sftp->login($host, $username, $password, $port); } else { file_put_contents($publicKeyFile, $publicKey); file_put_contents($privateKeyFile, $privateKey); $sftp->loginPubKey($host, $username, $publicKeyFile, $privateKeyFile, $passPhrase, $port); unlink($publicKeyFile); unlink($privateKeyFile); } } catch (Exception $e) { KalturaLog::err("Import Batch Job [{$batchJobPartnerId}::{$batchJobId}] login failed: " . $e->getMessage()); if (file_exists($publicKeyFile)) {
/** * * @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 KalturaYahooDistributionProfile $distributionProfile * @return ftpMgr */ protected function getFTPManager(KalturaYahooDistributionProfile $distributionProfile) { $ftpHost = $distributionProfile->ftpHost; $ftpUsername = $distributionProfile->ftpUsername; $ftpPassword = $distributionProfile->ftpPassword; $ftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP); if (!$ftpManager) { throw new Exception("FTP manager not loaded"); } $ftpManager->login($ftpHost, $ftpUsername, $ftpPassword, null, true); return $ftpManager; }
/** * Load XML file * @param DropFolder $folder * @param DropFolderFile $file * @throws Exception */ private function getContentResources(DropFolder $folder, DropFolderFile $file) { KalturaLog::debug('Parsing content resources from Xml'); $contentResources = array(); $engineOptions = array('useCmd' => false, 'asperaTempFolder' => kConf::get('temp_folder') . '/aspera_upload'); $fileTransferManager = kFileTransferMgr::getInstance($folder->getFileTransferMgrType(), $engineOptions); $loginStatus = $folder->loginByCredentialsType($fileTransferManager); if ($fileTransferManager->fileSize($folder->getPath() . '/' . $file->getFileName()) > kDropFolderXmlEventsConsumer::MAX_XML_FILE_SIZE) { throw new Exception(DropFolderXmlBulkUploadPlugin::XML_FILE_SIZE_EXCEED_LIMIT_MESSAGE, DropFolderXmlBulkUploadPlugin::getErrorCodeCoreValue(DropFolderXmlBulkUploadErrorCode::XML_FILE_SIZE_EXCEED_LIMIT)); } $xmlPath = $folder->getLocalFilePath($file->getFileName(), $file->getId(), $fileTransferManager); KalturaLog::debug('Local XML path [' . $xmlPath . ']'); $xmlContent = $this->getOriginalOrTransformIfNeeded($folder, $xmlPath); $xmlDoc = new KDOMDocument(); $res = $xmlDoc->loadXML($xmlContent); $localResourceNodes = $xmlDoc->getElementsByTagName(kDropFolderXmlEventsConsumer::DROP_FOLDER_RESOURCE_NODE_NAME); foreach ($localResourceNodes as $localResourceNode) { $contentResources[] = $localResourceNode->getAttribute(kDropFolderXmlEventsConsumer::DROP_FOLDER_RESOURCE_PATH_ATTRIBUTE); } return $contentResources; }
/** * * @param KalturaAttUverseDistributionProfile $distributionProfile * @return ftpMgr */ protected function getFTPManager(KalturaAttUverseDistributionProfile $distributionProfile) { $host = $distributionProfile->ftpHost; $login = $distributionProfile->ftpUsername; $password = $distributionProfile->ftpPassword; $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $ftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP, $engineOptions); $ftpManager->login($host, $login, $password); return $ftpManager; }
/** * @param KalturaVerizonDistributionProfile $distributionProfile */ protected function fetchFilesList(KalturaVerizonVcastDistributionProfile $distributionProfile) { $host = $distributionProfile->ftpHost; $login = $distributionProfile->ftpLogin; $pass = $distributionProfile->ftpPass; $fileTransferMgr = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP); if (!$fileTransferMgr) { throw new Exception("FTP manager not loaded"); } $fileTransferMgr->login($host, $host, $pass); return $fileTransferMgr->listDir('/'); }
/** * * @param KalturaYahooDistributionProfile $distributionProfile * @return ftpMgr */ protected function getFTPManager(KalturaYahooDistributionProfile $distributionProfile) { $ftpHost = $distributionProfile->ftpHost; $ftpUsername = $distributionProfile->ftpUsername; $ftpPassword = $distributionProfile->ftpPassword; $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $engineOptions['passiveMode'] = true; $ftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::FTP, $engineOptions); if (!$ftpManager) { throw new Exception("FTP manager not loaded"); } $ftpManager->login($ftpHost, $ftpUsername, $ftpPassword); return $ftpManager; }
/** * * @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; }
/** * * @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 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('/'); }
function delete() { $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $engineOptions['passiveMode'] = $this->data->ftpPassiveMode; $engine = kFileTransferMgr::getInstance($this->protocol, $engineOptions); try { $engine->login($this->data->serverUrl, $this->data->serverUsername, $this->data->serverPassword); $engine->delFile($this->destFile); } catch (kFileTransferMgrException $ke) { throw new kApplicativeException($ke->getCode(), $ke->getMessage()); } 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 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 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; }
/** * * @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; }
/** * Init a kFileTransferManager acccording to folder type and login to the server * @throws Exception * * @return kFileTransferMgr */ public static function getFileTransferManager(KalturaDropFolder $dropFolder) { $engineOptions = isset(KBatchBase::$taskConfig->engineOptions) ? KBatchBase::$taskConfig->engineOptions->toArray() : array(); $fileTransferMgr = kFileTransferMgr::getInstance(self::getFileTransferMgrType($dropFolder->type), $engineOptions); $host = null; $username = null; $password = null; $port = null; $privateKey = null; $publicKey = null; if ($dropFolder instanceof KalturaRemoteDropFolder) { $host = $dropFolder->host; $port = $dropFolder->port; $username = $dropFolder->username; $password = $dropFolder->password; } if ($dropFolder instanceof KalturaSshDropFolder) { $privateKey = $dropFolder->privateKey; $publicKey = $dropFolder->publicKey; $passPhrase = $dropFolder->passPhrase; } // login to server if ($privateKey || $publicKey) { $privateKeyFile = self::getTempFileWithContent($privateKey, 'privateKey'); $publicKeyFile = self::getTempFileWithContent($publicKey, 'publicKey'); $fileTransferMgr->loginPubKey($host, $username, $publicKeyFile, $privateKeyFile, $passPhrase, $port); } else { $fileTransferMgr->login($host, $username, $password, $port); } return $fileTransferMgr; }
/** * * @param KalturaQuickPlayDistributionProfile $distributionProfile * @return sftpMgr */ protected function getSFTPManager(KalturaQuickPlayDistributionProfile $distributionProfile) { $host = $distributionProfile->sftpHost; $login = $distributionProfile->sftpLogin; $pass = $distributionProfile->sftpPass; $sftpManager = kFileTransferMgr::getInstance(kFileTransferMgrType::SFTP); $sftpManager->login($host, $login, $pass); return $sftpManager; }