2016-09-06 15:32:52 +02:00
|
|
|
<?php
|
|
|
|
$dir = dirname(__FILE__);
|
|
|
|
|
|
|
|
include_once($dir.'/../../../config/config.inc.php');
|
|
|
|
|
|
|
|
$host = Configuration::get('PHILEA_MAGISTOR_FTP_SVR');
|
|
|
|
$username = Configuration::get('PHILEA_MAGISTOR_FTP_USER');
|
|
|
|
$password = Configuration::get('PHILEA_MAGISTOR_FTP_PWD');
|
|
|
|
$mode = Configuration::get('PHILEA_MAGISTOR_FTP_MODE'); // "active" ou "passive"
|
|
|
|
$namefilelocal = 'local.txt';
|
|
|
|
|
|
|
|
global $regex_file_in,$regex_file_out;
|
|
|
|
|
|
|
|
$handle = fopen($namefilelocal,'r');
|
|
|
|
echo 'debut du traitement '.date('G:i:s d/m/Y').chr(10);
|
|
|
|
|
|
|
|
// connection au serveur ftp de Magistor
|
|
|
|
|
|
|
|
$id_ftp = ftp_connect($host) or die("Couldn't connect to $host"); ;
|
|
|
|
//identification
|
|
|
|
if(!ftp_login($id_ftp,$username,$password))
|
|
|
|
die('erreur lors de l\'identification FTP'.chr(10).chr(10));
|
|
|
|
|
|
|
|
//activation du mode passif
|
|
|
|
if($mode)
|
|
|
|
if(!ftp_pasv($id_ftp,true))
|
|
|
|
die('erreur lors de l\'activation du mode passif'.chr(10).chr(10));
|
|
|
|
|
|
|
|
//récupération des fichiers de sortie magistor
|
|
|
|
$list=ftp_nlist($id_ftp,'./OUT');
|
|
|
|
if(isset($regex_file_in))
|
|
|
|
{
|
|
|
|
foreach($list as $file)
|
|
|
|
{
|
|
|
|
$name_file = str_replace('./OUT/','',$file);
|
|
|
|
if(!preg_match($regex_file_in, $name_file))
|
|
|
|
continue;
|
|
|
|
touch($dir.'/IN/'.$name_file);
|
|
|
|
chmod($dir.'/IN/'.$name_file,0777);
|
|
|
|
$handle = fopen($dir.'/IN/'.$name_file,'w+');
|
|
|
|
if(!ftp_fget($id_ftp,$handle,$file,1))
|
|
|
|
print('erreur lors de l\'ouverture du fichier : '.$file.chr(10));
|
|
|
|
else
|
|
|
|
{
|
2016-09-16 17:33:23 +02:00
|
|
|
ftp_fput($id_ftp,'archives/'.$name_file,$handle,FTP_BINARY);
|
2016-09-06 15:32:52 +02:00
|
|
|
ftp_delete($id_ftp,$file);
|
|
|
|
}
|
|
|
|
fclose($handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//envoie des fichiers d'entré magistor
|
|
|
|
$list = scandir('OUT/');
|
|
|
|
if(isset($regex_file_out))
|
|
|
|
{
|
|
|
|
foreach($list as $file)
|
|
|
|
{
|
|
|
|
if(!preg_match($regex_file_out, $file))
|
|
|
|
continue;
|
|
|
|
if($file == '.' || $file == '..')
|
|
|
|
continue;
|
|
|
|
if(!ftp_put ($id_ftp,'IN/'.$file,'OUT/'.$file,FTP_BINARY))
|
|
|
|
print('erreur lors de l\'ouverture du fichier : '.$file.chr(10));
|
|
|
|
else
|
|
|
|
unlink('OUT/'.$file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|