tSCPFileExists - 6.1

Talend Components Reference Guide

EnrichVersion
6.1
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

tSCPFileExists properties

Component family

Internet/SCP

 

Function

This component checks, over a fully encrypted channel, if a file exists on a remote host.

Purpose

tSCPFileExists allows you to verify the existence of a file on the defined SCP server.

Basic settings

Host

SCP IP address.

Port

Listening port number of the SCP server.

Username

SCP user name.

Authentication method

SCP authentication method.

Password

SCP password.

To enter the password, click the [...] button next to the password field, and then in the pop-up dialog box enter the password between double quotes and click OK to save the settings.

Remote directory

File path on the remote directory.

Filename

Name of the file to check.

Global Variables

ERROR_MESSAGE: the error message generated by the component when an error occurs. This is an After variable and it returns a string. This variable functions only if the Die on error check box is cleared, if the component has this check box.

FILENAME: the name of the file being processed. This is a Flow variable and it returns a string.

STATUS: the execution result of the component. This is an After variable and it returns a string.

A Flow variable functions during the execution of a component while an After variable functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl + Space to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio User Guide.

Usage

This component is typically used as a single-component sub-job but can also be used with other components.

Log4j

If you are using a subscription-based version of the Studio, the activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User Guide.

For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html.

Limitation

n/a

Handling a file using SCP

In this scenario, a six-component Job checks if a defined file exists in a specified directory on a remote SCP server, and returns a message to indicate the result of the verification. If the file doesn't exist in that directory, the Job will put the local file to the SCP server, and then get the file from the SCP server to another defined local directory to verify that the file has been uploaded correctly.

Dropping and linking the components

  1. Add the following six components by typing their names on the design workspace or dropping them from the Palette to the design workspace: tSCPConnection, tSCPFileExists, tJava, tSCPPut, tSCPGet, and tSCPClose.

  2. Connect the tSCPConnection component to the tSCPFileExists component using a Trigger > On Subjob Ok connection.

  3. Connect the tSCPFileExists component to the tJava component using a Trigger > On Component Ok connection, and to the tSCPPut component using a Trigger > Run if connection.

  4. Connect the tSCPPut component to the tSCPGet component using a Trigger > On Subjob Ok connection.

  5. Connect the tSCPGet component to the tSCPClose component using a Trigger > On Subjob Ok connection.

Configuring the tSCPConnection component

  1. Double-click the tSCPConnection component to open its Basic settings view.

  2. Enter the host name or IP address of the SCP server and the port number in the corresponding field.

  3. Enter the user name used for connection in the Username field.

  4. Select Password from the Authentication method drop-down list.

  5. Click the [...] button next to the Password text box, then in the pop-up [Enter a new password] dialog box, enter the password between double quotes and click OK to save the change.

Configuring file existence verification

  1. Double-click the tSCPFileExists component to open its Basic settings view.

  2. Select the Use an existing connection check box and then select the connection you have configured from the Component List.

  3. In the Filename field, enter the name of the file to be checked between double quotes. In this example, it is "testscp.txt".

  4. Double-click the tJava component to open its Basic settings view.

  5. In the Code field, enter the following code:

    System.out.println((String)globalMap.get("tSCPFileExists_1_FILENAME"));
    System.out.println((String)globalMap.get("tSCPFileExists_1_STATUS"));
  6. Select the Component tab and click the If connection to open its Basic settings view.

  7. In the Condition field, enter the following code:

    !((String)globalMap.get("tSCPFileExists_1_STATUS")).equals("File exists.")

    This way, if the file doesn't exist in the defined directory, the rest of the Job will be executed.

Configuring the tSCPPut component

  1. Double-click the tSCPPut component to open its Basic settings view.

  2. Select the Use an existing connection check box and then select the connection you have configured from the Component List.

  3. Click the [+] button to add one row in the Filelist table, and enter the full local path of the file to be uploaded in the corresponding Source column. In this example, it is "D:/SCPPut/testscp.txt".

Configuring the tSCPGet component

  1. Double-click the tSCPGet component to open its Basic settings view.

  2. Select the Use an existing connection check box and then select the connection you have configured from the Component List.

  3. In the Local directory field, enter or click the [...] button to browse to the directory under which the file will be stored. In this example, it is "D:/SCPGet".

  4. Select append from the Overwrite or Append drop-down list.

  5. Click the [+] button to add one row in the Filelist table, and then enter the path of the file to be retrieved from the SCP server in the corresponding Source column. In this example, it is "./testscp.txt".

Configuring the tSCPClose component

  1. Double-click the tSCPClose component to open its Basic settings view.

  2. Select the connection you have configured from the Component List.

Executing the Job

  1. Press Ctrl+S to save the Job.

  2. Make sure the file testscp.txt exists in the local directory D:/SCPPut, and does not exist in the local directory D:/SCPGet and the home directory of the SCP server.

  3. Press F6 to run the Job.

    The file verification information is displayed on the Run console.

  4. Go to the local directory D:/SCPGet and the home directory of the SCP server, you will see the file testscp.txt there.