ComposantsComponents

ComposantsComponents › Internet › FTP

tFTPTruncate

tFTPTruncate

Internet / FTP

Vide des fichiers sur un serveur FTP, FTPS ou SFTP : chaque fichier du Répertoire distant dont le nom correspond à un masque de la table Fichiers est ramené à 0 octet, sous le même nom. Rien n'est supprimé ni créé. Usage type : remettre à zéro un journal ou un fichier de cumul après l'avoir récupéré. Le composant ouvre sa propre connexion ou se sert de celle d'un tFTPConnection. Sa description dans la palette (« Deletes files using the File Transfert Protocol ») est reprise du tFTPDelete : elle est fausse. Empties files on an FTP, FTPS or SFTP server: each file of the Remote directory whose name matches a mask of the Files table is brought down to 0 bytes, under the same name. Nothing is deleted or created. Typical use: reset a log or an accumulation file after fetching it. The component opens its own connection or uses the one of a tFTPConnection. Its description in the palette ("Deletes files using the File Transfert Protocol") is taken from the tFTPDelete: it is wrong.

EntréeInput

Aucune : il peut commencer un sous-job. Sinon un lien Iterate (tout le composant à chaque itération) ou Main, qui ne sert pas à choisir les fichiers (comme pour le tFTPDelete). None: it can start a subjob. Otherwise one Iterate link (the whole component at each iteration) or Main link, which cannot choose the files (as for the tFTPDelete).

SortieOutput

Facultative. Iterate : une itération par ligne de la table Fichiers, après son traitement. Main : les lignes reçues, inchangées, une fois par ligne de la table. Optional. Iterate: one iteration per row of the Files table, after it is processed. Main: the rows received, unchanged, once per row of the table.

Déclencheurs en sortieOutput triggers

On Subjob Ok On Subjob Error On Component Ok On Component Error Run if

UtilisationUsage

Récupérer un journal, puis le remettre à zéroFetch a log, then reset it

OnSubjobOk OnSubjobOk OnSubjobOk tFTPConnection_1 tFTPGet_1 tFTPTruncate_1 tFTPClose_1

Le tFTPGet copie app.log sur la machine du job ; s'il a réussi, le tFTPTruncate le vide sur le serveur. Le fichier garde son nom : l'application qui l'écrit peut continuer d'y ajouter des lignes. Ce qui a été écrit entre les deux composants est perdu. The tFTPGet copies app.log to the machine of the job; if it succeeded, the tFTPTruncate empties it on the server. The file keeps its name: the application that writes it can go on adding lines to it. What was written between the two components is lost.

  1. Déposez le tFTPTruncate depuis la famille Internet › FTP de la palette. Drop the tFTPTruncate from the Internet › FTP family of the palette.
  2. Cochez Utiliser une connexion existante et choisissez le tFTPConnection, ou renseignez le serveur comme dans un tFTPConnection. Check Use an existing connection and choose the tFTPConnection, or fill in the server as in a tFTPConnection.
  3. Donnez le Répertoire distant et une ligne de Fichiers par masque, aussi précis que possible : "app.log" plutôt que "*". Give the Remote directory and one row of Files per mask, as precise as possible: "app.log" rather than "*".
  4. Lisez NB_FILE après le composant : un masque qui ne trouve rien ne provoque aucune erreur. Read NB_FILE after the component: a mask that finds nothing causes no error.

Paramètres simplesBasic settings

Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Les champs de texte sont des expressions Java. Le composant n'a pas de case Arrêter en cas d'erreur : tout refus l'arrête. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. Text fields are Java expressions. The component has no Die on error box: any refusal stops it.

La connexionThe connection

Utiliser une connexion existante décochée, le composant ouvre sa propre connexion, la ferme à la fin, et montre les réglages du serveur. Ce sont, avec les mêmes libellés, défauts et conditions d'affichage, ceux du tFTPConnection, décrits sur sa page : Type de propriété, Hôte ("localhost"), Port (21, 990 en FTPS, à passer à 22 en SFTP), Utilisateur ("anonymous"), Mot de passe, Support de SFTP, Support de FTPS, la Méthode d'authentification SFTP et sa clé, le magasin de clés et le Mode de sécurité FTPS, le Mode de connexion (Passif), l'encodage, et en paramètres avancés le proxy Socks, la protection du canal FTPS, le délai et le parsage strict. With Use an existing connection unchecked, the component opens its own connection, closes it at the end, and shows the server settings. They are, with the same labels, defaults and display conditions, those of the tFTPConnection, described on its page: Property Type, Host ("localhost"), Port (21, 990 over FTPS, to be set to 22 over SFTP), Username ("anonymous"), Password, SFTP Support, FTPS Support, the SFTP Authentication method and its key, the FTPS keystore and Security Mode, the Connection Mode (Passive), the encoding, and as advanced settings the Socks proxy, the FTPS channel protection, the timeout and the strict parsing.

Seules différences : les noms techniques USERNAME et PASSWORD (USER et PASS dans le tFTPConnection), et le défaut du Mot de passe, "suomynona" au lieu d'un texte vide. Le paramètre avancé Ignorer les erreurs à la fermeture (FTP) est propre au composant. Only differences: the technical names USERNAME and PASSWORD (USER and PASS in the tFTPConnection), and the default of the Password, "suomynona" instead of an empty text. The advanced setting Ignore Failure At Quit (FTP) belongs to the component.

ParamètreSetting DéfautDefault VisibleShown Description
Utiliser une connexion existanteUse an existing connectionUSE_EXISTING_CONNECTION NonNo ToujoursAlways Cochée : le composant prend la connexion ouverte par le tFTPConnection choisi, sans l'ouvrir ni la fermer ; le protocole est celui de ce tFTPConnection. Checked: the component takes the connection opened by the chosen tFTPConnection, without opening or closing it; the protocol is the one of that tFTPConnection.
Liste des composantsComponent listCONNECTION videempty Utiliser une connexion existante cochéeUse an existing connection checked Le tFTPConnection du job dont la connexion est utilisée. The tFTPConnection of the job whose connection is used.
Répertoire distantRemote directoryREMOTEDIR "." ToujoursAlways Dossier du serveur où les masques s'appliquent. En FTP, le composant s'y place (CWD) ; absent, les masques sont ignorés sans erreur, sauf avec une connexion existante et Déplacer vers le répertoire courant coché (Failed to change remote directory. 550 …). En SFTP, il en lit la liste et met ce dossier devant chaque nom ; absent, le composant s'arrête (2: No such file). Folder of the server where the masks apply. Over FTP, the component goes into it (CWD); missing, the masks are ignored without an error, except with an existing connection and Move to the current directory checked (Failed to change remote directory. 550 …). Over SFTP, it reads its listing and puts this folder in front of each name; missing, the component stops (2: No such file).
Déplacer vers le répertoire courantMove to the current directoryMOVE_TO_THE_CURRENT_DIRECTORY OuiYes Connexion existante FTP ou FTPSExisting FTP or FTPS connection Cochée : la connexion partagée passe dans le Répertoire distant et y reste après le composant (essai : dossier courant /work ensuite). Décochée : le dossier est ajouté devant chaque masque et la connexion revient à son dossier de départ (essai : /). Checked: the shared connection moves into the Remote directory and stays there after the component (run: current folder /work afterwards). Unchecked: the folder is put in front of each mask and the connection goes back to its starting folder (run: /).
Utiliser des Expressions Regex Perl5 en tant que masque de fichier (décocher signifie utiliser les Expressions globales)Use Perl5 Regex Expressions as Filemask (Unchecked means Glob Expressions)PERL5_REGEX NonNo ToujoursAlways Décochée : jokers (*, ?, […]), comparés au nom entier, casse comprise. Cochée : expressions régulières Java. Mêmes règles que le tFTPDelete. Unchecked: wildcards (*, ?, […]), compared with the whole name, case-sensitively. Checked: Java regular expressions. Same rules as the tFTPDelete.
FichiersFilesFILES videempty ToujoursAlways Une colonne Masque de fichier (FILEMASK), une expression Java par ligne : "app.log", "*.log". Les lignes sont traitées l'une après l'autre. En FTP, un masque peut viser un sous-dossier ("sub/*.log") ; un sous-dossier absent est ignoré sans erreur. Pas en SFTP (voir Pièges). Un masque sans correspondance ne crée aucun fichier. One Filemask column (FILEMASK), one Java expression per row: "app.log", "*.log". The rows are processed one after the other. Over FTP, a mask can target a sub-folder ("sub/*.log"); a missing sub-folder is ignored without an error. Not over SFTP (see Pitfalls). A mask without a match creates no file.

Paramètres avancésAdvanced settings

En plus de ceux de la connexion (voir tFTPConnection) : Besides those of the connection (see tFTPConnection):

ParamètreSetting DéfautDefault VisibleShown Description
Ignorer les erreurs à la fermeture (FTP)Ignore Failure At Quit (FTP)IGNORE_FAILURE_AT_QUIT NonNo FTP (sans FTPS ni SFTP), connexion propre ou existanteFTP (neither FTPS nor SFTP), own or existing connection Cochée : une erreur pendant la déconnexion de la connexion propre du composant est ignorée, son message rangé dans ERROR_MESSAGE. Sans effet avec une connexion existante, que le composant ne ferme pas. Checked: an error during the disconnection of the component's own connection is ignored, its message stored in ERROR_MESSAGE. No effect with an existing connection, which the component does not close.

Variables globalesGlobal variables

NB_FILE
Integer, Nombre de fichiers, disponible après le composant : fichiers vidés, toutes lignes confondues. null pendant son exécution.Integer, Number of files, available after the component: files emptied, all rows together. null while it runs.
CURRENT_STATUS
String, Statut, ligne par ligne de Fichiers : No file truncated. au début de chaque ligne, File truncate OK. après un fichier vidé, File truncate fail. juste avant l'erreur qui arrête le composant. Après le composant, seule la dernière ligne compte.String, Current Status, row by row of Files: No file truncated. at the start of each row, File truncate OK. after an emptied file, File truncate fail. just before the error that stops the component. After the component, only the last row counts.
ERROR_MESSAGE
String : message de l'erreur qui a arrêté le composant (refus du serveur, liste illisible), à lire dans un lien On Component Error.String: message of the error that stopped the component (refusal of the server, unreadable listing), to read in an On Component Error link.
((Integer) globalMap.get("tFTPTruncate_1_NB_FILE"))
((String) globalMap.get("tFTPTruncate_1_CURRENT_STATUS"))
((String) globalMap.get("tFTPTruncate_1_ERROR_MESSAGE"))

Ce que fait vraiment le composantWhat the component really does

Aucun des deux protocoles n'a de commande « tronquer » : le composant réécrit chaque fichier choisi avec un contenu vide. Lu dans son modèle et vu dans les journaux des serveurs d'essai : Neither protocol has a "truncate" command: the component rewrites each chosen file with an empty content. Read in its template and seen in the logs of the test servers:

FTP / FTPS

Pour chaque ligne : liste des noms du dossier (NLST, sans le type des entrées), puis, pour chaque nom qui correspond, un envoi de 0 octet sous ce nom (STOR), comme un tFTPPut d'un fichier vide. Le serveur remplace le contenu du fichier. Un dossier qui correspond est envoyé lui aussi, et le refus du serveur arrête le composant. For each row: listing of the names of the folder (NLST, without the type of the entries), then, for each matching name, an upload of 0 bytes under that name (STOR), like a tFTPPut of an empty file. The server replaces the content of the file. A matching folder is sent too, and the refusal of the server stops the component.

SFTP

Pour chaque ligne : liste du Répertoire distant (entrées . et .. comprises sur notre serveur), puis, pour chaque nom qui correspond, ouverture du fichier en écriture avec remise à zéro (WRITE,CREATE,TRUNCATE dans le journal) et fermeture sans rien écrire : c'est le même fichier, vidé. Une entrée qui est un dossier (. compris) arrête le composant. For each row: listing of the Remote directory (. and .. entries included on our server), then, for each matching name, opening of the file for writing with reset (WRITE,CREATE,TRUNCATE in the log) and closing without writing anything: it is the same file, emptied. An entry that is a folder (. included) stops the component.

Seuls des fichiers qui existent sont touchés : "new.log", absent, n'a rien créé (NB_FILE = 0), en FTP comme en SFTP. En FTP, si la liste ne peut pas être lue, le composant écrit Can't get file names from … Filemask … ignored sur la sortie d'erreur (sans Log4j) et passe à la ligne suivante. Only files that exist are touched: "new.log", missing, created nothing (NB_FILE = 0), over FTP as over SFTP. Over FTP, if the listing cannot be read, the component writes Can't get file names from … Filemask … ignored to the error output (without Log4j) and goes on with the next row.

ExemplesExamples

Les sorties sont copiées depuis des exécutions du job (lancé depuis Talaxie, Java 21) contre des serveurs d'essai installés sur le poste : un serveur FTP et FTPS aux réponses de type Unix, et un serveur SFTP (OpenSSH sftp-server). Utilisateur "demo", Répertoire distant "/work", qui contient app.log (45 octets), err.log (9), data.csv (5) et sub/old.log (4) ; réglages par défaut sauf mention contraire. Les lignes du journal du serveur montrent les commandes reçues (extraits). Le tJava relié par On Subjob Ok est : The outputs are copied from runs of the job (started from Talaxie, Java 21) against test servers installed on the machine: an FTP and FTPS server with Unix-like replies, and an SFTP server (OpenSSH sftp-server). User "demo", Remote directory "/work", which holds app.log (45 bytes), err.log (9), data.csv (5) and sub/old.log (4); default settings unless stated otherwise. The lines of the server log show the commands received (excerpts). The tJava connected with On Subjob Ok is:

System.out.println("NB_FILE = " + globalMap.get("tFTPTruncate_1_NB_FILE"));
System.out.println("CURRENT_STATUS = " + globalMap.get("tFTPTruncate_1_CURRENT_STATUS"));
System.out.println("ERROR_MESSAGE = " + globalMap.get("tFTPTruncate_1_ERROR_MESSAGE"));

Les *.log, en FTPThe *.log files, over FTP

Fichiers : "*.log". Files: "*.log".

NB_FILE = 2
CURRENT_STATUS = File truncate OK.
ERROR_MESSAGE = null
[ftp] 54672 > CWD /work
[ftp] 54672 < 250 Directory successfully changed.
[ftp] 54672 > NLST
[ftp] 54672 > STOR app.log
[ftp] 54672 < 150 Ok to send data (BINARY).
[ftp] 54672 received 0 bytes
[ftp] 54672 < 226 Transfer complete.
[ftp] 54672 > STOR err.log
[ftp] 54672 < 150 Ok to send data (BINARY).
[ftp] 54672 received 0 bytes
[ftp] 54672 < 226 Transfer complete.

Après : app.log et err.log font 0 octet ; data.csv et sub/old.log n'ont pas changé. En FTPS explicite, même résultat, après AUTH TLS, PBSZ 0 et PROT P. After: app.log and err.log are 0 bytes; data.csv and sub/old.log did not change. Over explicit FTPS, same result, after AUTH TLS, PBSZ 0 and PROT P.

Le même, en SFTPThe same, over SFTP

Support de SFTP coché, même masque : SFTP Support checked, same mask:

NB_FILE = 2
CURRENT_STATUS = File truncate OK.
ERROR_MESSAGE = null
[sftp] sftp-server: opendir "/work"
[sftp] sftp-server: closedir "/work"
[sftp] sftp-server: open "/work/app.log" flags WRITE,CREATE,TRUNCATE mode 0666
[sftp] sftp-server: close "/work/app.log" bytes read 0 written 0
[sftp] sftp-server: open "/work/err.log" flags WRITE,CREATE,TRUNCATE mode 0666
[sftp] sftp-server: close "/work/err.log" bytes read 0 written 0

Mêmes fichiers vidés. Same files emptied.

Rien ne correspond, ou un sous-dossierNothing matches, or a sub-folder

"*.zip", en FTP comme en SFTP : "*.zip", over FTP as over SFTP:

NB_FILE = 0
CURRENT_STATUS = No file truncated.
ERROR_MESSAGE = null

FTP, deux lignes : "sub/*.log" puis "missing/*.log" : FTP, two rows: "sub/*.log" then "missing/*.log":

NB_FILE = 1
CURRENT_STATUS = No file truncated.
ERROR_MESSAGE = null

sub/old.log a été vidé (CWD /work/sub, STOR old.log) ; /work/missing n'existe pas (550), ligne ignorée sans erreur, et c'est son statut qui reste. En SFTP, ce masque se comporte tout autrement (voir Pièges). sub/old.log was emptied (CWD /work/sub, STOR old.log); /work/missing does not exist (550), row ignored without an error, and its status is the one left. Over SFTP, this mask behaves quite differently (see Pitfalls).

Sortie Iterate et connexion existanteIterate output and existing connection

Iterate tFTPTruncate_1 tJava_2

FTP, "*.log" puis "*.zip". tJava_2 affiche "iteration: …", le tJava relié par On Subjob Ok "after: …" : FTP, "*.log" then "*.zip". tJava_2 prints "iteration: …", the tJava connected with On Subjob Ok "after: …":

iteration: NB_FILE = null, CURRENT_STATUS = File truncate OK.
iteration: NB_FILE = null, CURRENT_STATUS = No file truncated.
after: NB_FILE = 2, CURRENT_STATUS = No file truncated.

Une itération par ligne de la table, après son traitement. Avec un tFTPConnection et "*.log", mêmes fichiers vidés ; la connexion est restée dans /work avec Déplacer vers le répertoire courant coché, et revenue à / case décochée. One iteration per row of the table, after it is processed. With a tFTPConnection and "*.log", same files emptied; the connection stayed in /work with Move to the current directory checked, and went back to / box unchecked.

PiègesPitfalls

SFTP : le sous-dossier d'un masque est ignoréSFTP: the sub-folder of a mask is ignored

En SFTP, le composant liste toujours le Répertoire distant et ne compare que la fin du masque. Fichiers : "sub/*.log" : Over SFTP, the component always lists the Remote directory and only compares the end of the mask. Files: "sub/*.log":

NB_FILE = 2
CURRENT_STATUS = File truncate OK.
ERROR_MESSAGE = null
[sftp] sftp-server: opendir "/work"
[sftp] sftp-server: closedir "/work"
[sftp] sftp-server: open "/work/app.log" flags WRITE,CREATE,TRUNCATE mode 0666
[sftp] sftp-server: close "/work/app.log" bytes read 0 written 0
[sftp] sftp-server: open "/work/err.log" flags WRITE,CREATE,TRUNCATE mode 0666
[sftp] sftp-server: close "/work/err.log" bytes read 0 written 0

Ce sont /work/app.log et /work/err.log qui ont été vidés, pas sub/old.log : leur contenu est perdu. En SFTP, mettez le sous-dossier dans le Répertoire distant ("/work/sub"). It is /work/app.log and /work/err.log that were emptied, not sub/old.log: their content is lost. Over SFTP, put the sub-folder in the Remote directory ("/work/sub").

"*" : tout est vidé, puis erreur"*": everything is emptied, then an error

FTP, Fichiers : "*" (nom du job remplacé par MyJob, pile abrégée) : FTP, Files: "*" (job name replaced with MyJob, shortened stack):

tFTPTruncate_1 - File 'sub' was not truncated. Error message: 550 sub: Is a directory.

Exception in component tFTPTruncate_1 (MyJob)
java.lang.RuntimeException: tFTPTruncate_1 - File 'sub' was not truncated. Error message: 550 sub: Is a directory.

	at demo.myjob_0_1.MyJob.tFTPTruncate_1Process(MyJob.java:542)
	…

app.log, data.csv et err.log ont été vidés, puis le dossier sub, qui suit dans la liste, a été refusé par le serveur et le job s'est arrêté (code 1). En SFTP, "*" s'arrête dès la première entrée, ., sans rien vider : 4: /work/. is a directory. Aucun réglage ne permet de passer outre. app.log, data.csv and err.log were emptied, then the sub folder, next in the listing, was refused by the server and the job stopped (code 1). Over SFTP, "*" stops at the first entry, ., without emptying anything: 4: /work/. is a directory. No setting can get past it.

Pas de retour en arrièreNo way back

Le contenu vidé n'est conservé nulle part. Récupérez le fichier d'abord (tFTPGet) et reliez le tFTPTruncate par On Subjob Ok ou On Component Ok, pour qu'il ne s'exécute que si la copie a réussi. The emptied content is kept nowhere. Fetch the file first (tFTPGet) and connect the tFTPTruncate with On Subjob Ok or On Component Ok, so that it only runs if the copy succeeded.

Testez NB_FILETest NB_FILE

Un masque sans correspondance, un Répertoire distant ou un sous-dossier absents en FTP passent sans erreur, et CURRENT_STATUS ne décrit que la dernière ligne de Fichiers. NB_FILE compte les fichiers vraiment vidés. A mask without a match, a missing Remote directory or sub-folder over FTP go through without an error, and CURRENT_STATUS only describes the last row of Files. NB_FILE counts the files really emptied.

Flux d'entréeInput flow

Comme pour le tFTPDelete, la table Fichiers est évaluée avant la première ligne d'un lien Main entrant : row1.name y vaut null. Pour un fichier par ligne, passez par un tFlowToIterate et (String) globalMap.get("row1.name"). As for the tFTPDelete, the Files table is evaluated before the first row of an incoming Main link: row1.name is null there. For one file per row, go through a tFlowToIterate and (String) globalMap.get("row1.name").

Jusqu'à Talaxie 9.0.6 : cases affichées à tortUp to Talaxie 9.0.6: boxes shown wrongly

Les conditions d'affichage qui dépendent du tFTPConnection choisi ne sont pas évaluées : Déplacer vers le répertoire courant et Ignorer les erreurs à la fermeture (FTP) sont affichées dans tous les cas, en SFTP compris, où elles n'ont aucun effet. La colonne Visible ci-dessus donne l'affichage du Studio. À partir de Talaxie 9.0.7, ces conditions lisent le tFTPConnection choisi, et les cases s'affichent comme dans le Studio. The display conditions that depend on the chosen tFTPConnection are not evaluated: Move to the current directory and Ignore Failure At Quit (FTP) are shown in all cases, over SFTP included, where they have no effect. The Shown column above gives the display of the Studio. From Talaxie 9.0.7, these conditions read the chosen tFTPConnection, and the boxes are shown as in the Studio.

Voir aussiSee also