Exemplo n.º 1
0
 * @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));
 }
Exemplo n.º 3
0
    CAppUI::setMsg("Document de prescription non valide", UI_MSG_ERROR);
    redirect();
}
// Envoi de la prescription par sur un seveurFTP
// Envoi à la source créée 'PrescriptionLabo' (FTP)
$prescriptionlabo_source = CExchangeSource::get("prescriptionlabo", "ftp");
// Creation du FTP
$ftp = new CFTP();
$ftp->init($prescriptionlabo_source);
if (!$ftp->hostname) {
    CAppUI::setMsg("Le document n'a pas pu être envoyé, configuration FTP manquante", UI_MSG_ERROR);
    redirect();
}
// Transfert
$destination_basename = "Prescription-" . $mbPrescription->_id;
$file = "tmp/dPlabo/export_prescription.xml";
try {
    $ftp->connect();
    $ftp->sendFile($file, "{$destination_basename}.xml");
} catch (CMbException $e) {
    $e->stepAjax();
    $ftp->close();
    redirect();
}
$ftp->close();
CAppUI::setMsg("Document envoyé", UI_MSG_OK);
// Créer le document joint
if ($msg = $doc->addFile($mbPrescription)) {
    CAppUI::setMsg("Document non attaché à la prescription: {$msg}", UI_MSG_ERROR);
}
redirect();