Search code examples
talend

Reading from a password file for tftpconnection


I am trying to use tFTPConnection to download certain files from an FTP site.

It is a regular FTP connection, connecting on port 21.

I would like to be able to read the password from a file rather than hard coding the password to the job.

At the minute I'm simply making the connection and then printing success:

Current job layout

Any advice on how this could be approached or solved?


Solution

  • Talend supports the idea of context variables which allow you to define at run time the values used for them.

    This is typically used so you can "contextualise" a connection and then deploy the job in multiple environments and have the connection be to the environment specific end point.

    For instance, a job might need to connect to a database but that database is different for each of a development, a testing and a production environment.

    Instead of hard coding the connection parameters to the job we instead create some context variables under a context group and refer to these context variables in the connection parameters:

    Contextualised tMySqlConnection

    Now, at run time we have the Talend job load these contexts from a file with the relevant connection parameters using an implicit context load:

    Example implicit context load settings

    In this case, the job will read the context variables at run time from a CSV called test.csv that looks like:

    Example contexts file

    Now, when this job is ran it will attempt to connect to localhost:3306/test with the root user and an empty password.

    If we have another context file on another machine (but with the same file path) then this could refer to a database on some other server or simply using different credentials and the job would connect to this other database instead.

    For your use case you can simply create a single context group with the FTP connection settings, including the password (or potentially just contextualise the password), and then refer to it in the same way:

    Contextualised password with a tFtpConnection component