Component family |
Internet/SCP |
|
Function |
This component checks, over a fully encrypted channel, if a file |
|
Purpose |
tSCPFileExists allows you to |
|
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 |
|
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 FILENAME: the name of the file being processed. This is a STATUS: the execution result of the component. This is an A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see Talend Studio |
|
Usage |
This component is typically used as a single-component sub-job but |
|
Log4j |
The activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User 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 |
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.
-
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. -
Connect the tSCPConnection component to
the tSCPFileExists component using a
Trigger > On
Subjob Ok connection. -
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. -
Connect the tSCPPut component to the
tSCPGet component using a Trigger > On Subjob
Ok connection. -
Connect the tSCPGet component to the
tSCPClose component using a Trigger > On Subjob
Ok connection.
-
Double-click the tSCPConnection component
to open its Basic settings view. -
Enter the host name or IP address of the SCP server and the port number in
the corresponding field. -
Enter the user name used for connection in the Username field.
-
Select Password from the Authentication method drop-down list.
-
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.
-
Double-click the tSCPFileExists component
to open its Basic settings view. -
Select the Use an existing connection
check box and then select the connection you have configured from the
Component List. -
In the Filename field, enter the name of
the file to be checked between double quotes. In this example, it is
“testscp.txt”. -
Double-click the tJava component to open
its Basic settings view. -
In the Code field, enter the following
code:12System.out.println((String)globalMap.get("tSCPFileExists_1_FILENAME"));System.out.println((String)globalMap.get("tSCPFileExists_1_STATUS")); -
Select the Component tab and click the
If connection to open its Basic settings view. -
In the Condition field, enter the
following code:1!((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.
-
Double-click the tSCPPut component to
open its Basic settings view. -
Select the Use an existing connection
check box and then select the connection you have configured from the
Component List. -
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”.
-
Double-click the tSCPGet component to
open its Basic settings view. -
Select the Use an existing connection
check box and then select the connection you have configured from the
Component List. -
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”. -
Select append from the Overwrite or Append drop-down list.
-
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”.
-
Double-click the tSCPClose component to
open its Basic settings view. -
Select the connection you have configured from the Component List.
-
Press Ctrl+S to save the Job.
-
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. -
Press F6 to run the Job.
The file verification information is displayed on the Run console.
-
Go to the local directory D:/SCPGet and
the home directory of the SCP server, you will see the file testscp.txt there.