public static function getMediaFTP($host, $user, $pass, $server, $local, $file, $hashing = false) { $label = Player_Flags::getFlag('playlist', 'media'); Player_File::setDir($local); $done = array(); foreach ($file as $key => $value) { if (self::connect($host)) { if (self::login($user, $pass)) { $hostpath = explode('/', $server); foreach ($hostpath as $dir) { self::chdir($dir); } if (!in_array($value[$label['file']], $done)) { $i = 1; do { Player_Debug::setDebug($value[$label['file']], 1); $result = true; self::get($local . $value[$label['file']], $value[$label['file']]); $log = self::getLastResult(); if ($log == self::FTP_COMMAND_OK || $log == self::FTP_FILE_ACTION_OK || $log == self::FTP_FILE_TRANSFER_OK || $log == self::FTP_PASSIVE_MODE) { if ($hashing) { $hash = Player_Encrypt::setHashFile($local . $value[$label['file']]); if ($value[$label['hash']] === $hash) { $result = false; array_push($done, $value[$label['file']]); } } else { $result = false; array_push($done, $value[$label['file']]); } self::disconnect(); } else { Player_Debug::setDebug('Error downloading ' . $value[$label['file']] . '. Trying again.', 2); Player_Debug::setDebug('Fail: ' . $i++ . '; Log: ' . $log, 3); if ($i > 5) { Player_Debug::setDebug('Canceling download after ' . $i++ . ' failed tries.' . Player_Debug::getTab() . '"' . $value[$label['file']] . '"', 1); return false; } } } while ($result); } } self::disconnect(); } else { return false; } } if (count($done) == count($file)) { return true; } }
public function setMedias() { Player_Debug::setStatus('Downloading media...'); $environment = $this->getEnvironment(); $url = Player_Flags::getFlag('url'); $media = Player_Flags::getFlag('playlist', 'media'); $label = Player_Flags::getFlag('label'); $path = Player_Flags::getFlag('path'); $ftp = Player_Flags::getFlag('ftp'); $connect = $this->loadConnection($environment, $url['access']); $access = Player_Convert::getXML($connect, $label['ftp']); $local = $path['media']; $temp = $path['media'] . $path['temp']; $playlist = $this->getPlaylist(); Player_Debug::setDebug('Listing files to download...'); Player_File::setPermissions($local, 0777); $download = array(); foreach ($playlist as $key => $value) { if (isset($value[$media['index']])) { foreach ($value[$media['index']] as $k => $v) { if (!empty($v[$media['filename']])) { if (!in_array($v[$media['filename']], $this->getFiles())) { if (file_exists($local . $v[$media['filename']])) { $hash = Player_Encrypt::setHashFile($local . $v[$media['filename']]); if ($hash !== $v[$media['hash']]) { Player_Debug::setDebug('Corrupted files:"' . Player_Debug::getTab() . '"' . $v[$media['filename']] . '"', 1); Player_File::setPermissions($local . $v[$media['filename']]); array_push($download, array($media['file'] => $v[$media['filename']], $media['hash'] => $v[$media['hash']])); } } else { if (file_exists($temp . $v[$media['filename']])) { $hash = Player_Encrypt::setHashFile($temp . $v[$media['filename']]); if ($hash !== $v[$media['hash']]) { Player_Debug::setDebug('Corrupted files:' . Player_Debug::getTab() . '"' . $v[$media['filename']] . '"', 1); Player_File::setPermissions($temp . $v[$media['filename']]); array_push($download, array($media['file'] => $v[$media['filename']], $media['hash'] => $v[$media['hash']])); } } else { Player_Debug::setDebug('Download:' . Player_Debug::getTab() . '"' . $v[$media['filename']] . '"', 1); array_push($download, array($media['file'] => $v[$media['filename']], $media['hash'] => $v[$media['hash']])); } } $this->setFiles($v[$media['filename']]); } } } } } $refresh = count($download) > 0 ? true : false; $this->setRefresh($refresh); if (!$refresh) { Player_Debug::setDebug('No files for download.', 1); return true; } Player_Debug::setDebug('Downloading files...'); if (Player_Connect_FTP::getMediaFTP($access[$ftp['host']], $access[$ftp['user']], $access[$ftp['pass']], $access[$ftp['file']], $temp, $download, true)) { return true; } return false; }