tFTPGet with SFTP.

Highlighted
One Star

tFTPGet with SFTP.

Hi everyone,
This isn't so much a question as it is sharing how I solved the problem with tFTPDelete and tFTPPut with SFTP support using a password as an authentication method. I was tasked with getting files from an SFTP location then moving a copy of the file to another location within the SFTP host and removing the original file. For some reason I was able to use tFTPGet to actually get the files but then it would error out on either tFTPDelete or tFTPPut (with SFTP). The error would always say File Not Found or something along those lines. However the file was in fact there!!!
At any rate I ended with a job like this:
tFTPGet -----on sub job ok---> tJava

In tFTPGet I did what I needed to get the file from the SFTP location.
In tJava I used JSch as follows:
com.jcraft.jsch.JSch jsch = new com.jcraft.jsch.JSch();
//create SSH connection
String host = "some.ftp.com";
String user = "user";
String password = "password";//sftp password



com.jcraft.jsch.Session session = jsch.getSession(user, host, 22);
session.setPassword(password);

java.util.Properties config=new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);

session.connect();
System.out.println(session.isConnected());

String command = "cd out; cp *.txt ../out_done/; rm *.txt";

try {

com.jcraft.jsch.Channel channel = session.openChannel("exec");
channel.setInputStream(null);
channel.setOutputStream(System.out);

((com.jcraft.jsch.ChannelExec) channel).setCommand(command);
channel.connect();
java.io.InputStream in = null;
byte[] tmp = new byte;
while (true) {

if (channel.isClosed()) {
System.out.println("exit-status:"+channel.getExitStatus());
break;
}
try {
Thread.sleep(1000);
}
catch (Exception ee) {
}
}
channel.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}


session.disconnect();

Hope someone else finds this useful/helpful.
Community Manager

Re: tFTPGet with SFTP.

Hi
Thanks for your sharing!Smiley Wink
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog