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

abdullahkhan852
Tera Contributor

Hi @Ankur Bawiskar @Ravindra Kaja @Chuck Tomasi @Jeff Hausman @Ravi Gaurav ,

I want to   Fetch a file name from an SFTP server and dynamically update a Data Source file path in ServiceNow Flow Designer
Step 1 - inputs

abdullahkhan852_0-1754068224022.png

 

Step 2 - SFTP STEP

abdullahkhan852_1-1754068273631.png

 

STEP 3 - SCRIPT STEP 

 

abdullahkhan852_2-1754068312777.png

abdullahkhan852_3-1754068341995.png

 

STEP 4 - OUTPUT

abdullahkhan852_4-1754068362860.png

 

@Ravindra Kaja can you please the whole screenshots of your steps as I'm getting empty output .
Please help me to  get the filename through sftp and do share your  whole screenshots.