bebeboutik/modules/philea_magistor/script/connection_ftp.php
2017-07-25 16:54:35 +02:00

73 lines
2.1 KiB
PHP

<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = 80;
$dir = dirname(__FILE__);
include_once($dir.'/../../../config/config.inc.php');
$host = Configuration::get('PHILEA_MAGISTOR_FTP_SVR');
$host2 = Configuration::get('PHILEA_MAGISTOR_FTP_SVR_2');
$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
if(($id_ftp = ftp_connect($host)) == false){
$id_ftp = ftp_connect($host2) or die("Couldn't connect to $host and $host2");
$mode = "passive";
}
//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 == "passive")
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
{
//ftp_fput($id_ftp,'archives/'.$name_file,$handle,FTP_BINARY);
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);
}
}
?>