One Star

TFTPConnection

Hi there
Could someone help me please. I have zip files that go onto an FTP Server. I want to connect to that server and then check if the file exists in my local folder on my local machine, if the files arent there i want them added to another folder say folder C.
How do i do this using ftpConnection,tFTPFileList,tfileexist to compare the files on the server and those on the local folder(So that it only pics the files not on folder).
10 REPLIES
Community Manager

Re: TFTPConnection

Hi
Iterate each file on ftp server with local files, it does not exist on local folder, get it using tFTPGet component. eg:
tFTPConnection
|
onsubjobok
|
tFTPFileList_1--iterate--tJava_1--oncomponentok---tFileList_1--iterate---tJava_2
---runIf--tFTPGet
tFTPFileList_1: iterate each file on ftp server.
tJava_1: get the current file name on ftp server and put it to a global variable.
String currentServerFilename=
((String)globalMap.get("tFTPFileList_1_CURRENT_FILE"));
globalMap.put("serverFileName",currentServerFilename);
tFileList: iterate each file in local folder
tJava_2:
String currentLocalFilename=((String)globalMap.get("tFileList_1_CURRENT_FILE"));
if(currentLocalFilename.equals((String)globalMap.get("serverFileName"))){
globalMap.put("isExist", true);
}else{
globalMap.put("isExist", false);
}
set the condition of RunIf:
!(Boolean)globalMap.get("isExist")
let us know if you have any trouble.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: TFTPConnection

Hi Shong,
I have done as stated above and i changed the location folder for the FtpGet component to another folder. So it still searches for the files in a local folder and ftp server and if not found in local folder it gets that file. What i have realised is it is actually getting the same files that are in the local folder instead.Could you help me please.
Community Manager

Re: TFTPConnection

Hello
Modify the code on tJava_2 to:
String currentLocalFilename=((String)globalMap.get("tFileList_1_CURRENT_FILE"));
if(currentLocalFilename.equals((String)globalMap.get("serverFileName"))){
globalMap.put("isExist", true);
break;
}else{
globalMap.put("isExist", false);
}

Waiting for your feedback!
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: TFTPConnection

Hi Shong
For some reason i am still picking the file in local folder too.
I think i am going wrong somewhere.
I have folder Input Files. It has 2 zip files in there and i have folder Zipped2 which is the folder i want to have only the files on ftp server AND not in the input files stored.
The code for the Jave processes is exactly as you said here. Is it the way am putting the information in the propeties section for my components.
This is what i have for the components:
TFTPList_1 ---> Using an existing connection
Remote Directory -->\New "this is where the zip files r on the server"
Filemask --> "*.zip"

TFileList_1 -->
Directory-->"C:/Users/Pheona.Sanyamahwe/Documents/Pheona/Talend/OPC Talend Project/InputFiles" //the local folder where my files are..

TFTPGet_3 -->
LocalDirectory -->"C:/Users/Pheona.Sanyamahwe/Documents/Pheona/Talend/OPC Talend Project/Zipped2"// this is the file where files on ftpserver and not in InputFile folder are stored
Remote Direcroy-->"/New"
OverWrite File -->never
FileMask -->"*.zip"
Is there something i am doing wrong?
Community Manager

Re: TFTPConnection

Hi
TFTPGet_3 -->
LocalDirectory -->"C:/Users/Pheona.Sanyamahwe/Documents/Pheona/Talend/OPC Talend Project/Zipped2"// this is the file where files on ftpserver and not in InputFile folder are stored
Remote Direcroy-->"/New"
OverWrite File -->never
FileMask -->"*.zip"

Here the file mask should be the name of current server file. eg:
(String)globalMap.put("serverFileName");

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: TFTPConnection

Shong
am i supposed to declare the string here before the code for the filemask because the code seems not to work,
i am getting this file error
the method put(String,Object) in the type Map<String,object> not applicable for this argument
my code is
(String)globalMap.put("winstanley@ftp.copdtrak.org")
Community Manager

Re: TFTPConnection

Hi
Sorry, the file mask should be the name of current server file. eg:
(String)globalMap.get("serverFileName");
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: TFTPConnection

Hi Shong
thanks for the help
I have another question if you dont mind. I am getting a java null pointer exception error in one of my Tmaps.
It has a delimited file which is the input file and amysql table as a lookup.
input file Lookup table
Name Name
File Include
the inner join is on the name variable if the name is the same and the value is Y in the lookup table then i want that Name and File sent to the next output file
for those that arent = to Y r sent to an error file. The value for include can be Y or Null in the lookup table.
I tried using the following in my expression field for the right output row5(lookup table) -->row5.Include.equals(Y)
that will not work
i do not want the names with no Y to be sent to the next output table how can i do this, as it keeps giving me the error message
Community Manager

Re: TFTPConnection

Hi
Please report a new topic for new question and I will answer you on new topic, I do NOT want this topic to be your specifics topic for all questions.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: TFTPConnection

what if we use tftpfileexist using file pattern?
what i observed is whenever we are having multiple files with same pattern it is returning false? any idea how to overcome this?