One Star

Iterating file in FTP directories using tLoop

Hi all,
Im a newbie in Talend Open Studio.
I want to iterate all files in the numbers of FTP directories, about more than 500 directories, then process those all files with another subjob. The name of directories are defined and set as global variable as array.
Here my SubJob :
tFTPConnection---On Subjob Ok-->tSetGlobalVar---On Subjob Ok-->tJava_1---On Sunjob Ok-->tLoop--iterate--->tFTPFilelist--iterate-->tJava_2
my Setting
1. tSetGlobalVar:
key=dir, value=new java.util.ArrayList<String>()
2. tJava_1
List<String> dir = (List<String>)globalMap.get("dir");
dir.add("bps1100");
dir.add("bps1200");
dir.add("bps1300");
dir.add("bps1400");
......
3. tLoop
for , from=0,to=((List<String>)globalMap.get("dir")).size()-1,step=1
4. tFTPFilelist
remote dir= "/shped/"+((List<String>)globalMap.get("dir")).get(((Integer)globalMap.get("tLoop_1_CURRENT_VALUE")))
5. tJava_2 to check the list of files
System.out.println(((String)globalMap.get("tFTPFileList_1_CURRENT_FILEPATH")));
Problem :
- iteration only work at first directory, and stop execution with error in the next directory, this is error message:
Exception in component tFTPFileList_1
2: No such file
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2287)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:1740)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:1757)
at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1195)
at shped.test3_0_1.test3.tLoop_1Process(test3.java:1310)
at shped.test3_0_1.test3.tJava_1Process(test3.java:1198)
at shped.test3_0_1.test3.tSetGlobalVar_1Process(test3.java:579)
at shped.test3_0_1.test3.tFTPConnection_1Process(test3.java:489)
Anything wrong? How then I can recovered this?
1 REPLY
Community Manager

Re: Iterating file in FTP directories using tLoop

Hi
tForeach component is the best component to complete your request, you can use tForeach to replace tSetglobalvar tjava tloop components in the job, please read its user manual on Talend Help Center.
https://help.talend.com/search/all?query=tForeach&content-lang=en
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business