Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

dynamic file name in FTPget

Hi, Please help.
I need to get the files "fill_*_tst.txt" from sFTP server.
When I specify the file name, it works. but I tried to create a dynamic name, it is not working in tFTPget.
HEre is the code I input in 'filemask", which can be wrong.
"fill_" + TalendDate.formatDate("yyyyMMdd", TalendDate.getCurrentDate()) + "_*_tst.txt"
How can I do that?
Thank you.
Labels (2)
15 Replies
jkrfs
Creator
Creator

Im confused, you first say
"fill_*_tst.txt"
but then you add the date, is this correct? if you were going by the original pattern, shouldnt it be:
fill_" + TalendDate.formatDate("yyyyMMdd", TalendDate.getCurrentDate()) + "_tst.txt" ?
Remember, in filemask, using * is a wildcard character...
_AnonymousUser
Specialist III
Specialist III
Author

Sorry I wasn't clear.
Files in the server are named as "fil_20100721_2222_tst.txt" or "fil_20100721_2223_tst.txt".
So I want to get all the files for "fil_YYYYMMDD_*_tst.txt" with wild card in it.
_AnonymousUser
Specialist III
Specialist III
Author

So when I tested with a filename (fill_20100720_*_tst.txt), it worked throuhg tFTPget. but I need to generate the file name everyday.
jkrfs
Creator
Creator

Personally, I like to set my dates in the beginning of the flow using tJava using a context parameter.
First, create a context parameter something like context.todaysDate
Then in the beginning of the flow add a tJava and connect it with SubJobOk to the next in the flow. Add this in the component code:
GregorianCalendar instance = new GregorianCalendar();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
context.todaysDate = formatter.format(instance.getTime());
Then you will use this in the filemask:
"fill_" + context.todaysDate + "_*_tst.txt"
Its a little more work, but that way I can just use one set context parameter throughout the job, and its easier to handle overall.
_AnonymousUser
Specialist III
Specialist III
Author

Thanks a lot. I will try it.
_AnonymousUser
Specialist III
Specialist III
Author

Does it require any imports?
_AnonymousUser
Specialist III
Specialist III
Author

somehow it doesn't work. simply I tried to add String variable in tJava code as following.
String filename = "fil_20100720_2226_tst.txt";
And tFTPget, I put file mask 'filename' but I get an error "filename cannot be resolved". How can I call the variable from filemask? do you have an example? Thanks for your help.
_AnonymousUser
Specialist III
Specialist III
Author

Hi, I tried your code but I got this error.
context.todaysDate cannot be resolved or is not a field

Personally, I like to set my dates in the beginning of the flow using tJava using a context parameter.
First, create a context parameter something like context.todaysDate
Then in the beginning of the flow add a tJava and connect it with SubJobOk to the next in the flow. Add this in the component code:
GregorianCalendar instance = new GregorianCalendar();
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
context.todaysDate = formatter.format(instance.getTime());
Then you will use this in the filemask:
"fill_" + context.todaysDate + "_*_tst.txt"
Its a little more work, but that way I can just use one set context parameter throughout the job, and its easier to handle overall.
Anonymous
Not applicable

Hi,
The FileMask value expected in your case is :
"fil_"+TalendDate.getDate("YYYYMMDD")+"_*_tst.txt"
Let me know if that resolve your issue.
The function TalendDate.getDate("DATE_PATTERN") return the current date of your machine/server and format it following the expected format.
For example you date is YYYYMMDD : It's return 20100722; if your date is YYYY-DD-MM : It's return 2010-22-07.
Using my FileMask in your tFTPGet will GET all the files start by : fil_20100722_ - and finishing by _tst.txt
Have a good test.
Best regards;