The CreatorCon Call for Content is officially open! Get started here.

retrieve SFTP data

lokesho
Kilo Explorer

Hi,

How to retrieve the SFTP data into service now..
Any suggestions would be great help!

8 REPLIES 8

jason_petty
Tera Expert

Just create a Data Source and in the File Retrieval Method you can choose SFTP. and set up all your credentials and paths accordingly and test it.


lokesho
Kilo Explorer

Hi Jason,

Thanks a lot for the information!

I have created a data source with all set up like file path, import set table etc and I can able to load the data from the SFTP.
The challenge is I will get the data every day with the below format
YYYYMMDD.csv.
So I am thinking of schedule the file import daily but I am not sure how to implement this.
Could you please help on this..

Thanks,
Lokesh


The solution that I sent automatically processes it once it comes in. But if your data source record is always the same record, you just create a scheduled import and select the data source.


lokesho
Kilo Explorer

Hi Jason,

Thanks for the information Jason..!

I have created the scheduled import and selected the required datasource. Its working fine.
The challenge is file name changes every day in the sftp server..
example: YYYYMMDD.csv.
I am thinking of updating the file path in the Datasource form with the below script. but its not updating the file path to the current date in datasource.
I am writting below script after checking the execute pre-import script in the scheduled import form.
Could you please help me on this..?

var ds = new GlideRecord('sys_data_source');
ds.addQuery('name', 'name of the datasource');
ds.query();
while(ds.next()) {
var d = GlideDate();
// d.addDays(-1);
var dayOfMonth = d.getDayOfMonth().toString();
if (dayOfMonth.length == 1) {
dayOfMonth = '0' + dayOfMonth;
}
var month = d.getMonth().toString();
if (month.length == 1) {
month = '0' + month;
}

var year = d.getYear().toString();

var filename = 'CWY_EMP_' + year + month + dayOfMonth + '.csv';
// var filename = 'CWY_EMP_20130806.csv';


current.file_path = "/cwyibmsftp/from_conway/" + filename;
//current.u_postscript = "rm /apps/people-crypt1/" + filename;
current.update();

}