* @version $Revision: 6069 $ * @author SARL OpenXtrem * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html */ // Check params if (null == ($exchange_source_name = CValue::get("exchange_source_name"))) { CAppUI::stepAjax("Aucun nom de source d'échange spécifié", UI_MSG_ERROR); } $exchange_source = CExchangeSource::get($exchange_source_name, "ftp", false, null, false); $ftp = new CFTP(); $ftp->init($exchange_source); try { $ftp->testSocket(); CAppUI::stepAjax("CFTP-success-connection", E_USER_NOTICE, $ftp->hostname, $ftp->port); $ftp->connect(); CAppUI::stepAjax("CFTP-success-authentification", E_USER_NOTICE, $ftp->username); if ($ftp->passif_mode) { CAppUI::stepAjax("CFTP-msg-passive_mode"); } $sent_file = CAppUI::conf('root_dir') . "/offline.php"; $remote_file = $ftp->fileprefix . "test.txt"; $ftp->sendFile($sent_file, $remote_file); CAppUI::stepAjax("CFTP-success-transfer_out", E_USER_NOTICE, $sent_file, $remote_file); $get_file = "tmp/offline.php"; $ftp->getFile($remote_file, $get_file); CAppUI::stepAjax("CFTP-success-transfer_in", E_USER_NOTICE, $remote_file, $get_file); $ftp->delFile($remote_file); CAppUI::stepAjax("CFTP-success-deletion", E_USER_NOTICE, $remote_file); } catch (CMbException $e) { $e->stepAjax(); }
/** * Populate archive directory up to max_archives files * * @param CFTP $ftp FTP connector * @param string $basename Base name for archive directory * @param boolean $compressed True if file is an archive * * @return int Current archive count */ function archiveFile(CFTP $ftp, $basename, $compressed) { try { // Répertoire d'archivage $directory = $ftp->fileprefix . $basename; $datetime = $this->getDateTime(); $ftp->createDirectory($directory); // Transmission de la copie $archive = "{$directory}/archive-{$datetime}" . ($compressed ? ".zip" : ".html"); $file = $compressed ? $this->_file_compressed : $this->_file; $ftp->sendFile($file, $archive); // Rotation des fichiers $files = $ftp->getListFiles($directory); rsort($files); $list_files = array_slice($files, $this->max_archives); foreach ($list_files as $_file) { $ftp->delFile($directory . "/" . basename($_file)); } } catch (CMbException $e) { $e->stepAjax(); } return count($ftp->getListFiles($directory)); }
$list = array_slice($list, 0, $count); foreach ($list as $filepath) { if (substr($filepath, -strlen($extension)) == $extension) { $filename = basename($filepath); $hprimFile = $ftp->getFile($filepath, "tmp/hprim21/{$filename}"); // Création de l'échange $echg_hprim21 = new CEchangeHprim21(); $echg_hprim21->group_id = CGroups::loadCurrent()->_id; $echg_hprim21->sender_class = $sender_ftp->_class; $echg_hprim21->sender_id = $sender_ftp->_id; $echg_hprim21->date_production = CMbDT::dateTime(); $echg_hprim21->store(); $hprimReader = new CHPrim21Reader(); $hprimReader->_echange_hprim21 = $echg_hprim21; $hprimReader->readFile($hprimFile); // Mapping de l'échange $echg_hprim21 = $hprimReader->bindEchange($hprimFile); if (!count($hprimReader->error_log)) { $echg_hprim21->message_valide = true; $ftp->delFile($filepath); } else { $echg_hprim21->message_valide = false; CAppUI::stepAjax("Erreur(s) pour le fichier '{$filepath}' : {$hprimReader->error_log}", UI_MSG_WARNING); } $msg = $echg_hprim21->store(); $msg ? CAppUI::stepAjax("Erreur lors de la création de l'échange : {$msg}", UI_MSG_WARNING) : CAppUI::stepAjax("L'échange '{$echg_hprim21->_id}' a été créé."); unlink($hprimFile); } else { $ftp->delFile($filepath); } }