How to pull file using SFTP data source with dynamic filename

Ravindra Kaja
Tera Expert

Client is placing file on SFTP server everyday with filename appending with date and time. Ex: name-2023-03-14-15-03-52.csv.

 

I tried the filename using wild card character like "name-2023-03-14*.csv" but its not working. Is there a way to get the file having timestamp appended at the end?

 

 

1 ACCEPTED SOLUTION

Below are the steps:

In the SFTP step available OOB (requires Integration Hub subscription), using Get File List command we can pass source path and get the file names present in that folder. This command also accept filenames with wild card character to get specific files. In our case, filename appends with timestamp at the end. So we passed filename as “<filename>_*.csv” and retrieved complete filename shown below.

 

RavindraKaja_0-1681369947371.png

 

Output:

 

 

RavindraKaja_2-1681371021801.png

 

Using script, we can read the filename and pass it over to the SFTP data source which pulls data from the server.

 

Other commands like Copy Files To This Instance are also available which will reduce multiple SFTP calls to the server.

 

PS: To make this work, you should allow connection between mid server and SFTP server.

View solution in original post

10 REPLIES 10

@Ravindra Kaja 

for that you will have to use Mid Server script include which uses java language + javascript.

fetch the latest file from that sftp folder and return it back to servicenow.

then update it in data source

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Found a way to make it work without much scripting. 

Using SFTP step available in flow, we can get the file name using wild card characters and use the name wherever required. 

 

Thank you all for your inputs

@Ravindra Kaja 

please share the detailed steps with screenshots so that it helps future readers as well.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Below are the steps:

In the SFTP step available OOB (requires Integration Hub subscription), using Get File List command we can pass source path and get the file names present in that folder. This command also accept filenames with wild card character to get specific files. In our case, filename appends with timestamp at the end. So we passed filename as “<filename>_*.csv” and retrieved complete filename shown below.

 

RavindraKaja_0-1681369947371.png

 

Output:

 

 

RavindraKaja_2-1681371021801.png

 

Using script, we can read the filename and pass it over to the SFTP data source which pulls data from the server.

 

Other commands like Copy Files To This Instance are also available which will reduce multiple SFTP calls to the server.

 

PS: To make this work, you should allow connection between mid server and SFTP server.

Hi @Ravindra Kaja @Ravindra Kaj @Ankur Bawiskar @Chuck Tomasi @Jeff Hausman @Ravi Gaurav ,
Im stuck with the step of SFTP to fetch file name from my server ,
i have followed the stes which you have suggested , but those seems to be incomplete since im unable the filename from the server .

Please share you screenshots of the full configuration as these are cropped.

please refer my steps and correct these .
STEP1 - INPUTS

abdullahkhan852_0-1754067439470.png


STEP 2 - SFTP STEP

abdullahkhan852_1-1754067564149.png

 STEP 3 - SCRIPT STEP 

 

abdullahkhan852_4-1754067665926.png

abdullahkhan852_5-1754067698703.png

 

Step 4 - Outputs

abdullahkhan852_6-1754067799636.png

Please refer this and guide me through this process to - 
Fetch a file name from an SFTP server and dynamically update a Data Source file path in ServiceNow Flow Designer.

Thanks.