SFTP Data Source with a changing filename

troyholmes
Giga Contributor

I have setup a Data Source that is pulling files from an SFTP server as the source. The system that places the file appends numbers to the end of each exported file so the name of the file changes each day.

The file path that works is /my_inboxes/venafi/Manged Non-F5 Certificates 161108-1100.CSV

The numbers at the end of the file change with each export.  

Is there a way in the file path to use a wild card or to just pickup all the files in the directory.

Troy Holmes

6 REPLIES 6

Deepak Kumar5
Kilo Sage

Write this script in Scheduled job pre-script. It will change the file name of data source before querying SFTP server.



var str = gs.daysAgo(0).replace( /-/g, "" );


var today = str.substring(2,8);



var path = "/my_inboxes/venafi/Manged Non-F5 Certificates "+today+"-1100.CSV";


var grd = new GlideRecord('sys_data_source');        


grd.addQuery('sys_id', 'sys_id of your data source');


grd.query();                  


while(grd.next()){


grd.file_path = path;


grd.update();


}


Deepak this is great. The one issue is the file time on the end may change slightly. What would happen if they generate the file at 1101 instead of 1100 is there a way to compensate for that issue.



Troy


It is hard to set name for the time. there would be always some difference is time when they put data. if they can remove it then it is better.


if there is any pattern in change then you can make it dynamic.


kdevireddy
Giga Contributor

Hi,



I have similar requirement and solution proposed by Deepak helped me to some extent. Can we use any wildcards or like name "starts with"


I tried but of no use. Any suggestions please.



Thanks,


Kiran