ComposantsComponents

ComposantsComponents › Internet › FTP

tFTPClose

tFTPClose

Internet / FTP

Ferme la connexion FTP, FTPS ou SFTP ouverte par un tFTPConnection du job, une fois que les autres composants FTP s'en sont servis. Il n'a qu'un réglage : la connexion à fermer. Les réglages de la connexion elle-même (protocoles, magasin de clés, authentification, délais, proxys) sont décrits sur la page du tFTPConnection. Closes the FTP, FTPS or SFTP connection opened by a tFTPConnection of the job, once the other FTP components have used it. It has only one setting: the connection to close. The settings of the connection itself (protocols, keystore, authentication, timeouts, proxies) are described on the tFTPConnection page.

EntréeInput

Aucune : il commence un sous-job, en général relié par On Subjob Ok ou depuis un tPostjob. Sinon un lien Iterate. None: it starts a subjob, usually connected by On Subjob Ok or from a tPostjob. Otherwise one Iterate link.

SortieOutput

Aucun flux ; un lien Iterate possible. No flow; an Iterate link is possible.

Déclencheurs en sortieOutput triggers

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

UtilisationUsage

À la fin de la chaîneAt the end of the chain

OnSubjobOk OnSubjobOk tFTPConnection_1 tFTPGet_1 tFTPClose_1

Simple, mais si un composant de la chaîne échoue, le tFTPClose n'est pas exécuté. Simple, but if a component of the chain fails, the tFTPClose is not run.

Dans le tPostjobIn the tPostjob

OnComponentOk tPostjob_1 tFTPClose_1

Le tPostjob s'exécute à la fin du job, même après une erreur : la connexion est fermée dans tous les cas (voir Exemples). The tPostjob runs at the end of the job, even after an error: the connection is closed in every case (see Examples).

  1. Déposez le tFTPClose depuis la famille Internet › FTP de la palette. Drop the tFTPClose from the Internet › FTP family of the palette.
  2. Choisissez dans Liste des composants le tFTPConnection dont il faut fermer la connexion. Choose in Component list the tFTPConnection whose connection must be closed.
  3. Reliez-le après le dernier composant qui utilise la connexion, ou au tPostjob. Connect it after the last component that uses the connection, or to the tPostjob.

Paramètres simplesBasic settings

Le libellé est celui de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Le composant n'a pas de paramètres avancés propres. The label is the one of the Component tab; the technical name, in grey, is the parameter name in the job file. The component has no advanced settings of its own.

ParamètreSetting DéfautDefault VisibleShown Description
Liste des composantsComponent listCONNECTION — ToujoursAlways Les tFTPConnection du job. Le protocole de celui qui est choisi (FTP, FTPS ou SFTP) décide, à la génération du code, de la façon de fermer. Sans connexion choisie, dans un job sans tFTPConnection, le job ne se compile pas : le code fait référence aux classes du client FTP, que rien n'ajoute au job. The tFTPConnection of the job. The protocol of the chosen one (FTP, FTPS or SFTP) decides, when the code is generated, how to close. With no connection chosen, in a job without tFTPConnection, the job does not compile: the code refers to the classes of the FTP client, which nothing adds to the job.

Variables globalesGlobal variables

Aucune variable propre. Quand la fermeture échoue, le composant range le message dans tFTPClose_1_ERROR_MESSAGE avant de relancer l'erreur. No variable of its own. When the closing fails, the component stores the message in tFTPClose_1_ERROR_MESSAGE before throwing the error again.

((String) globalMap.get("tFTPClose_1_ERROR_MESSAGE"))

Ce qu'il fermeWhat it closes

Le composant lit l'objet de la connexion dans globalMap (clé conn_tFTPConnection_1 pour tFTPConnection_1). S'il n'y en a pas, il ne fait rien. Sinon : The component reads the connection object in globalMap (key conn_tFTPConnection_1 for tFTPConnection_1). If there is none, it does nothing. Otherwise:

ConnexionConnection FermetureClosing Si elle échoueIf it fails
FTP et FTPSFTP and FTPS logout() : la commande QUIT, dont la réponse est attendue ; puis disconnect() : la connexion de commande est coupée.logout(): the QUIT command, whose reply is waited for; then disconnect(): the command connection is cut. Une connexion déjà fermée (deuxième tFTPClose) ou coupée par le serveur fait échouer QUIT : message dans ERROR_MESSAGE, erreur relancée. La connexion est quand même coupée (voir ci-dessous).A connection already closed (second tFTPClose) or cut by the server makes QUIT fail: message in ERROR_MESSAGE, error thrown again. The connection is still cut (see below).
SFTP Le canal SFTP puis la session SSH (channel.disconnect(), session.disconnect()).The SFTP channel then the SSH session (channel.disconnect(), session.disconnect()). Pas d'erreur attendue : fermer deux fois n'en a pas provoqué lors de nos essais.No error expected: closing twice caused none in our runs.

Une seconde fermeture, toujoursA second closing, always

Le composant a aussi une partie finally : à la fin de son sous-job, qu'il ait réussi ou échoué, la connexion est coupée une seconde fois (disconnect() sans QUIT en FTP et FTPS ; canal et session en SFTP), et une erreur à ce moment est ignorée. Quand QUIT échoue, la connexion n'est donc pas laissée ouverte. Cette partie ne s'exécute que si le tFTPClose lui-même est atteint. The component also has a finally part: at the end of its subjob, whether it succeeded or failed, the connection is cut a second time (disconnect() without QUIT for FTP and FTPS; channel and session for SFTP), and an error at that moment is ignored. When QUIT fails, the connection is thus not left open. This part only runs if the tFTPClose itself is reached.

L'objet reste dans globalMapThe object stays in globalMap

La clé conn_tFTPConnection_1 n'est pas retirée : un composant FTP placé après le tFTPClose trouve une connexion fermée et échoue (Connection is not open en FTP, Pipe closed en SFTP). Pour rouvrir, il faut repasser par un tFTPConnection. The conn_tFTPConnection_1 key is not removed: an FTP component placed after the tFTPClose finds a closed connection and fails (Connection is not open over FTP, Pipe closed over SFTP). To open again, a tFTPConnection must run again.

ExemplesExamples

Sorties copiées depuis des exécutions des jobs (lancés depuis Talaxie, Java 21) contre des serveurs FTP et SFTP d'essai installés sur le poste (127.0.0.1). Nom du job remplacé par MyJob, piles abrégées. Le tJava placé après le tFTPClose est : Outputs copied from runs of the jobs (started from Talaxie, Java 21) against test FTP and SFTP servers installed on the machine (127.0.0.1). Job name replaced with MyJob, shortened stacks. The tJava placed after the tFTPClose is:

// FTP, FTPS
org.apache.commons.net.ftp.FTPClient ftp = (org.apache.commons.net.ftp.FTPClient) globalMap.get("conn_tFTPConnection_1");
System.out.println("after tFTPClose: in globalMap: " + (ftp != null) + ", connected: " + ftp.isConnected());

// SFTP
com.jcraft.jsch.ChannelSftp sftp = (com.jcraft.jsch.ChannelSftp) globalMap.get("conn_tFTPConnection_1");
System.out.println("after tFTPClose: in globalMap: " + (sftp != null) + ", channel connected: " + sftp.isConnected()
    + ", session connected: " + sftp.getSession().isConnected());

Après un travail sur la connexion (FTP)After some work on the connection (FTP)

OnSubjobOk OnSubjobOk OnSubjobOk OnSubjobOk tFTPConnection_1 tFTPFileList_1 tFTPPut_1 tFTPClose_1 tJava_1

Liens On Subjob Ok. Fin du journal du serveur, puis la console : On Subjob Ok links. End of the log of the server, then the console:

[ftp] 59076 > QUIT
[ftp] 59076 < 221 Goodbye.
[ftp] 59076 closed
after tFTPClose: in globalMap: true, connected: false

En SFTP, le même job affiche after tFTPClose: in globalMap: true, channel connected: false, session connected: false. Le job complet, avec ses sorties, est sur la page du tFTPConnection. Over SFTP, the same job prints after tFTPClose: in globalMap: true, channel connected: false, session connected: false. The full job, with its outputs, is on the tFTPConnection page.

Rien à fermerNothing to close

OnSubjobOk OnSubjobOk OnSubjobOk tFTPClose_1 tJava_1 tFTPConnection_1 tFTPClose_2

tFTPClose_1 et tFTPClose_2 visent tous deux tFTPConnection_1, qui ne s'est pas encore exécuté quand tFTPClose_1 commence le job. tJava_1 : System.out.println("tJava_1: conn_tFTPConnection_1 = " + globalMap.get("conn_tFTPConnection_1")); tFTPClose_1 and tFTPClose_2 both target tFTPConnection_1, which has not run yet when tFTPClose_1 starts the job. tJava_1: System.out.println("tJava_1: conn_tFTPConnection_1 = " + globalMap.get("conn_tFTPConnection_1"));

tJava_1: conn_tFTPConnection_1 = null

tFTPClose_1 n'a rien fait et n'a pas signalé d'erreur ; tFTPClose_2 a fermé la connexion ouverte ensuite. Le job s'est terminé avec le code 0, en FTP comme en SFTP. Même chose quand le tFTPConnection a échoué ou n'a pas été exécuté (Run if) : un tFTPClose dans le tPostjob ne masque pas l'erreur d'origine. tFTPClose_1 did nothing and reported no error; tFTPClose_2 closed the connection opened afterwards. The job ended with code 0, over FTP as over SFTP. Same thing when the tFTPConnection failed or was not run (Run if): a tFTPClose in the tPostjob does not hide the original error.

Fermer deux foisClosing twice

OnSubjobOk OnSubjobOk OnSubjobOk tFTPConnection_1 tFTPClose_1 tFTPClose_2 tJava_1

Liens On Subjob Ok ; tFTPClose_2 a aussi un lien On Component Error vers un tJava qui affiche tFTPClose_2_ERROR_MESSAGE. En FTP : On Subjob Ok links; tFTPClose_2 also has an On Component Error link to a tJava that prints tFTPClose_2_ERROR_MESSAGE. Over FTP:

Exception in component tFTPClose_2 (MyJob)
java.io.IOException: Connection is not open
	at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:1213)
	…
	at org.apache.commons.net.ftp.FTP.quit(FTP.java:1018)
	at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:2458)
	…
On Component Error: tFTPClose_2_ERROR_MESSAGE = Connection is not open

tJava_1 n'est pas exécuté. En SFTP, le même job s'est déroulé sans erreur : tJava_1: after the second tFTPClose. tJava_1 is not run. Over SFTP, the same job ran without an error: tJava_1: after the second tFTPClose.

Le serveur a déjà coupé la connexionThe server already cut the connection

OnSubjobOk OnSubjobOk OnSubjobOk tFTPConnection_1 tJava_1 tFTPClose_1 tJava_2

Le tJava_1 arrête le serveur FTP d'essai et attend 3 s, comme un serveur qui coupe une connexion restée inactive ; tFTPClose_1 a un lien On Component Error qui affiche son message : tJava_1 stops the test FTP server and waits 3 s, like a server that cuts a connection left idle; tFTPClose_1 has an On Component Error link that prints its message:

tJava_1: test server stopped
Exception in component tFTPClose_1 (MyJob)
java.net.SocketException: Connection reset by peer
	at org.apache.commons.net.ftp.FTP.send(FTP.java:1109)
	…
	at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:2458)
	…
On Component Error: tFTPClose_1_ERROR_MESSAGE = Connection reset by peer

tJava_2, relié par On Subjob Ok, n'est pas exécuté : un serveur qui a fermé la connexion fait échouer la fin d'un job dont tout le travail a réussi. Voir Conseils. tJava_2, connected by On Subjob Ok, is not run: a server that closed the connection makes the end of a job fail although all its work succeeded. See Tips.

Fermeture dans le tPostjob, après une erreurClosing in the tPostjob, after an error

OnComponentOk Iterate OnComponentOk OnComponentOk tPrejob_1 tFTPConnection_1 tFTPFileList_1 tJava_1 tPostjob_1 tFTPClose_1 tJava_2

tFTPFileList_1, sur la connexion, liste "/missing", qui n'existe pas : tFTPFileList_1, on the connection, lists "/missing", which does not exist:

Exception in component tFTPFileList_1 (MyJob)
java.lang.RuntimeException: Failed to change remote directory. 550 /missing: No such directory.

	at demo.myjob_0_1.MyJob.tFTPFileList_1Process(MyJob.java:922)
	…
after tFTPClose: in globalMap: true, connected: false

Le job se termine avec le code 1, et la connexion est fermée. The job ends with code 1, and the connection is closed.

Conseils et limitesTips and limits

Toujours fermerAlways close

Sans tFTPClose, la connexion reste ouverte jusqu'à la fin de la JVM du job ; pour un job lancé dans une JVM qui dure (sous-job d'un tRunJob, service), elle peut occuper une session du serveur longtemps. Le tPostjob est la place la plus sûre. Without a tFTPClose, the connection stays open until the end of the JVM of the job; for a job run in a JVM that lasts (subjob of a tRunJob, service), it can hold a session of the server for a long time. The tPostjob is the safest place.

Ne pas faire échouer un job réussiNot failing a successful job

En FTP et FTPS, une erreur de fermeture (serveur qui a coupé une connexion inactive, connexion déjà fermée) n'a plus d'effet sur les fichiers transférés. Pour qu'elle n'arrête pas le job, reliez le tFTPClose par On Component Error à un composant qui la note (tWarn, tJava) : le job suit ce lien et se termine avec le code 0. Over FTP and FTPS, a closing error (server that cut an idle connection, connection already closed) no longer has any effect on the transferred files. So that it does not stop the job, connect the tFTPClose with On Component Error to a component that records it (tWarn, tJava): the job follows that link and ends with code 0.

Un tFTPClose par connexionOne tFTPClose per connection

Avec plusieurs tFTPConnection, chacun a besoin de son tFTPClose ; deux tFTPClose sur la même connexion FTP ou FTPS font échouer le second. With several tFTPConnection, each one needs its own tFTPClose; two tFTPClose on the same FTP or FTPS connection make the second one fail.

Composants sans connexion partagéeComponents without a shared connection

Un composant FTP qui ouvre sa propre connexion (sans Utiliser une connexion existante) la ferme lui-même à sa fin : le tFTPClose ne sert qu'aux connexions d'un tFTPConnection. An FTP component that opens its own connection (without Use an existing connection) closes it itself at its end: the tFTPClose is only for the connections of a tFTPConnection.

Voir aussiSee also