Transfert Check after file on FTP follow by CFTP or others
This commit is contained in:
parent
b1b1a932d7
commit
69a69f3209
188
README
188
README
@ -1,6 +1,148 @@
|
||||
Mise à disposition fichier de télétransmission
|
||||
----------------------------------------------
|
||||
|
||||
Configuration pour les fichiers en entrées
|
||||
------------------------------------------
|
||||
|
||||
'client' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => Nom de la prestation pour référence (UPPERCASE)
|
||||
'type' => Type du dépot SFTP|FTP
|
||||
'directory' => Répertoire de dépot (par defaut "send")
|
||||
'filemask' => Masque du fichier à récupérer ! not working
|
||||
'in' => array(
|
||||
--See the list of options--
|
||||
),
|
||||
'out' => array(
|
||||
--See the list of options--
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Send Options list (in)
|
||||
----------------------
|
||||
- CopyAddDate - Copy file and add a timestamp to the end of the filename
|
||||
- CopyDeleteAfter - After copying the file delete it in repository
|
||||
- RunWithEndFile - Only execute action when we receive file with extension .fin or .end
|
||||
- Log - Log transfert
|
||||
- Route - For each Route options (cp, ftp, sftp, mail)
|
||||
cp => realpath of dir
|
||||
ftp
|
||||
sftp
|
||||
mail
|
||||
- FilterName - Filtre par nom de prestation (true) ou par nom défini
|
||||
|
||||
Recv Options list (out)
|
||||
-----------------------
|
||||
- Log - Log read disable by default
|
||||
|
||||
Tck Options list (Check Transfert - use with CFT and other transfert mode)
|
||||
------------------------------------------------
|
||||
ALTER TABLE `flux_fileout` ADD `transfertDate` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `depotDateRead`;
|
||||
Envoi dans le repo du client fichier *.tck
|
||||
Recherche du fichier dans la table des flux et remplissage marqueur transfertDate
|
||||
|
||||
TODO
|
||||
----
|
||||
|
||||
Créer fileMail => Recupération element par mail, enregistrement
|
||||
Filtre sur email et/ou sujet
|
||||
Créer fileTransfert => envoi sur le FTP, SFTP du client
|
||||
|
||||
Note CFT
|
||||
========
|
||||
PARTNERS
|
||||
&PART Partner name (ID of CFTPART)
|
||||
&GROUP Group to which the partner belongs
|
||||
&SPART Sending partner name
|
||||
&RPART Receiving partner name
|
||||
&IPART Intermediate partner name
|
||||
&NPART Network name of partner sending data (NSPART or NRPART according to the transfer direction)
|
||||
|
||||
TRANSFER
|
||||
&IDT Transfer identifier
|
||||
&NIDT Protocol transfer identifier
|
||||
&IDTU Local transfer counter (unique)
|
||||
&PIDTU Parent idtu of the child transfers
|
||||
&PHASE Processing phases to help manage transfer flows
|
||||
&PHASESTEP Step in processing phase
|
||||
&APPSTATE State step for the processing script to restart if relaunched
|
||||
|
||||
&NSUB Counter for the submitting of end-of-transfer procedures, error procedures and procedures submitted by SUBMIT.
|
||||
If 4 characters long, the counter is reset to 1 after 9999
|
||||
&DIAGI Internal diagnostic code value
|
||||
&DIAGP Protocol diagnostic code value
|
||||
&COMP Compression negotiated for the transfer
|
||||
&NBT Number of bytes transferred
|
||||
&PRI Transfer CFT priority for the transfer (0 to 255)
|
||||
&QQ Number of the day in the year associated with the transfer identifier
|
||||
&SELFNAME Name of the generic transfer selection file
|
||||
&FCODE Code for the data in a file
|
||||
&TRTYPE Available at the end of transfer to designate FILE, MESSAGE, REPLY, or NACK
|
||||
&NCODE Code for the data sent over the network
|
||||
&EXITFREE Free communication area between multiple exits
|
||||
&XLATE Transcoding table used during transfer
|
||||
&MODE Server mode = ‘S’ transfer, Requester mode = ‘R’ transfer
|
||||
|
||||
FILE
|
||||
&IDF Model file identifier (logical name)
|
||||
&FNAME Physical file local name
|
||||
&FKEYLEN Length (received) of the indexed file key at the sender’s site
|
||||
&FKEYPOS Position (received) of the indexed file key at the sender’s site
|
||||
&NBR Number of records in the file
|
||||
&BLKNUM Catalog block number
|
||||
&XLATE Identifier of the translation table used
|
||||
&NBC Number of bytes in the transferred file
|
||||
&NIDF Model file network identifier
|
||||
&FDB Database name
|
||||
&FCHARSET Local file encoding
|
||||
&NCHARSET Destination file encoding for network data
|
||||
Receiving
|
||||
&NFNAME Physical file network name
|
||||
&UNIT Physical file volume name for received file (MVS, z/OS)
|
||||
&UNITC Physical file unit class for received file (MVS, z/OS)
|
||||
&PATH Local file path of the received file
|
||||
&ROOT Local file root for the received file
|
||||
&SUF Local file suffix for the received file
|
||||
Sending
|
||||
&SFNAME Name of file to send
|
||||
&FUNIT Physical file volume name for sending file (z/OS,MVS)
|
||||
&FUNITC Physical file unit for sending file (z/OS,MVS)
|
||||
&FPATH Prefix (file path) of the sending file
|
||||
&FROOT Root (actual file name) of the sending file
|
||||
&FSUF Suffix associated with file name of the sending file
|
||||
|
||||
DATE and TIME associated with a FILE
|
||||
&FDATE Date associated with the file
|
||||
&FTIME Time associated with the file
|
||||
&FYEAR Year associated with the file
|
||||
&FMONTH Month associated with the file
|
||||
&FDAY Day associated with the file
|
||||
|
||||
DATE and TIME associated with a CATALOG
|
||||
&CDATE Catalog entry date
|
||||
&CTIME Transfer start date
|
||||
&BTIME Transfer start time
|
||||
&BYEAR Start year for the transfer
|
||||
&BMONTH Start month for the transfer
|
||||
&BDAY Transfer start day
|
||||
&EDATE Transfer end date
|
||||
&ETIME Transfer end time f
|
||||
&EYEAR Transfer end year
|
||||
&EMONTH Transfer end month
|
||||
&EDAY Transfer end day
|
||||
&TT Transmission duration in seconds (TIMES attribute in the Transfer CFT catalog)
|
||||
|
||||
CONTROL OUTPUT
|
||||
&FLOG Name of last log file used by Transfer CFT
|
||||
&FACCNT Name of last statistics file used by Transfer CFT
|
||||
&FCAT Name of catalog used by Transfer CFT
|
||||
|
||||
Note INOTIFY
|
||||
============
|
||||
|
||||
Utilisation des événements INOTIFY pour la surveillance des dossiers
|
||||
|
||||
The command may contain these wildcards:
|
||||
@ -86,49 +228,3 @@ The following bits may be set in the mask field returned by read(2):
|
||||
|
||||
IN_UNMOUNT
|
||||
File system containing watched object was unmounted.
|
||||
|
||||
|
||||
|
||||
Configuration pour les fichiers en entrées
|
||||
------------------------------------------
|
||||
|
||||
'client' => array(
|
||||
'prestations' => array(
|
||||
array(
|
||||
'name' => Nom de la prestation pour référence (UPPERCASE)
|
||||
'type' => Type du dépot SFTP|FTP
|
||||
'directory' => Répertoire de dépot (par defaut "send")
|
||||
'filemask' => Masque du fichier à récupérer ! not working
|
||||
'in' => array(
|
||||
--See the list of options--
|
||||
),
|
||||
'out' => array(
|
||||
--See the list of options--
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Send Options list (in)
|
||||
----------------------
|
||||
- CopyAddDate - Copy file and add a timestamp to the end of the filename
|
||||
- CopyDeleteAfter - After copying the file delete it in repository
|
||||
- RunWithEndFile - Only execute action when we receive file with extension .fin or .end
|
||||
- Log - Log transfert
|
||||
- Route - For each Route options (cp, ftp, sftp, mail)
|
||||
cp => realpath of dir
|
||||
ftp
|
||||
sftp
|
||||
mail
|
||||
- FilterName - Filtre par nom de prestation (true) ou par nom défini
|
||||
|
||||
Recv Options list (out)
|
||||
-----------------------
|
||||
- Log - Log read disable by default
|
||||
|
||||
|
||||
TODO
|
||||
----
|
||||
|
||||
Créer fileMail => Recupération element par mail, enregistrement
|
||||
Filtre sur email et/ou sujet
|
||||
|
@ -74,6 +74,10 @@ if ( isset($opts->file) )
|
||||
{
|
||||
$extension = $pathParts['extension'];
|
||||
}
|
||||
// --- Don't play with *.tck files
|
||||
if ($extension == 'tck') {
|
||||
exit;
|
||||
}
|
||||
$client = basename(dirname($pathParts['dirname']));
|
||||
|
||||
// --- Base path, type and repository
|
||||
|
184
fileTck.php
Normal file
184
fileTck.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/**
|
||||
* Indicateur de transfert par un autre système
|
||||
* Attention le script doit s'executer avec l'utilisateur root
|
||||
*/
|
||||
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));
|
||||
|
||||
// Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Displays usage information.",
|
||||
'file|f=s' => "Give the full file path to integrate",
|
||||
'debug' => "Send a mail for debug",
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- Usage
|
||||
if( isset($opts->help) || count($opts->getOptions())==0 )
|
||||
{
|
||||
echo "Mark as transfert.\n";
|
||||
echo $opts->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
// --- Get the file
|
||||
if ( isset($opts->file) )
|
||||
{
|
||||
$optionsNoLog = false;
|
||||
$repositoryDir = 'send';
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
|
||||
// --- Get the main directory name in FTP and SFTP
|
||||
$pathParts = pathinfo($opts->file);
|
||||
$filenameIn = $pathParts['basename'];
|
||||
$extension = '';
|
||||
if (array_key_exists('extension', $pathParts))
|
||||
{
|
||||
$extension = $pathParts['extension'];
|
||||
}
|
||||
|
||||
// --- Only file with .tck
|
||||
if ($extension != 'tck') {
|
||||
exit;
|
||||
}
|
||||
|
||||
$client = basename(dirname($pathParts['dirname']));
|
||||
$filenameSearch = str_replace('.tck', '', $filenameIn);
|
||||
|
||||
// --- Base path, type and repository
|
||||
$startpos = strlen( $c->profil->path->data . DIRECTORY_SEPARATOR );
|
||||
if ('sftp' == substr($opts->file, $startpos, 4))
|
||||
{
|
||||
$type = 'SFTP';
|
||||
$fluxBasePath = $c->profil->path->sftp . '/' . $client;
|
||||
}
|
||||
elseif ('ftp' == substr($opts->file, $startpos, 3))
|
||||
{
|
||||
$type = 'FTP';
|
||||
$fluxBasePath = $c->profil->path->ftp . '/' . $client;
|
||||
}
|
||||
$fluxRepository = str_replace(array($fluxBasePath.'/', '/'.$filenameIn), array('', ''), $opts->file);
|
||||
|
||||
// --- Match prestation
|
||||
$prestations = include __DIR__ . '/fileConfig.php';
|
||||
$prestation = null;
|
||||
if (array_key_exists($client, $prestations))
|
||||
{
|
||||
$clientPrestations = $prestations[$client]['prestations'];
|
||||
foreach ($clientPrestations as $i => $p)
|
||||
{
|
||||
// --- Not default repository dir
|
||||
if (array_key_exists('directory', $p) && !empty($p['directory']))
|
||||
{
|
||||
$repositoryDir = $p['directory'];
|
||||
}
|
||||
|
||||
if ($type == $p['type'] && $fluxRepository == $repositoryDir)
|
||||
{
|
||||
$prestation = $p['name'];
|
||||
|
||||
// --- Set option
|
||||
if (array_key_exists('in', $p) && count($p['in']) > 0)
|
||||
{
|
||||
foreach ($p['in'] as $option => $value)
|
||||
{
|
||||
${'options'.$option} = $value;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fluxBasePath .= '/'.$repositoryDir;
|
||||
|
||||
// --- Prepare mail or Debug mode
|
||||
if ($opts->mail || $opts->debug)
|
||||
{
|
||||
$subject = "[Flux] - Transfert fichier $client";
|
||||
$txt = "Transfert d'un fichier\n";
|
||||
$txt.= "Client : $client\n";
|
||||
$txt.= "Fichier : ".$filenameIn."\n";
|
||||
|
||||
$mail = new Zend_Mail('UTF-8');
|
||||
// --- Configuration du transport SMTP
|
||||
if ( $c->profil->mail->method == 'smtp' ) {
|
||||
$config = array();
|
||||
if ( isset($this->config->auth) ) {
|
||||
$config['auth'] = $this->config->auth;
|
||||
if ( isset($this->config->username) ) {
|
||||
$config['username'] = $c->profil->mail->username;
|
||||
}
|
||||
if ( isset($this->config->password) ) {
|
||||
$config['password'] = $c->profil->mail->password;
|
||||
}
|
||||
}
|
||||
if ( isset($this->config->port) ) {
|
||||
$config['port'] = $c->profil->mail->port;
|
||||
}
|
||||
$tr = new Zend_Mail_Transport_Smtp($c->profil->mail->host, $config);
|
||||
}
|
||||
// --- Configuration transport Sendmail
|
||||
if ( $this->config->mail->method == 'sendmail' ) {
|
||||
$tr = new Zend_Mail_Transport_Sendmail();
|
||||
}
|
||||
$mail->setDefaultTransport($tr);
|
||||
$mail->setBodyText($txt);
|
||||
$mail->setFrom('supportdev@scores-decisions.com', 'Machine Flux');
|
||||
$mail->addTo('suivi@scores-decisions.com', 'Suivi');
|
||||
$mail->setSubject($subject);
|
||||
$mail->send();
|
||||
|
||||
// --- Stop
|
||||
if ($opts->mail) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Execute
|
||||
if ($optionsNoLog === false)
|
||||
{
|
||||
$db = Zend_Db::factory($c->profil->db->metier);
|
||||
Zend_Db_Table::setDefaultAdapter($db);
|
||||
try {
|
||||
$fluxM = new Application_Model_Sdv1FluxFileOut();
|
||||
$fluxM->update(array('transfertDate' => date('YmdHis')), "fileOut='".$filenameSearch."'");
|
||||
echo date('Y-m-d H:i:s')." - Enregistrement client:$client fichier:$filenameSearch\n";
|
||||
}
|
||||
catch (Zend_Db_Exception $e)
|
||||
{
|
||||
echo date('Y-m-d H:i:s')." - ERREUR Enregistrement client:$client fichier:$filenameSearch\n";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user