Tuesday, August 8, 2023

How to create a logic app in azure to move files in SFP from one folder to another

Go to Azure portal : Azure

You will see window like below


Click on "Create a resource"


A new window will open, there search for "Logic apps", as shown below


Now new window will come like below, select create > Logic App


Now new window will come like below


Enter the resource group, logic app name, select the region, select the plan type as consumption

Now click next > Next, you will see a window like below


Click on create

Deployment will take some time, now go to the resource
The moment you will go to resource, Logic app designer will be opened automatically like below


Go downwards and click on 'Blank logic app'


Logic app designer will open like below



Search for appropriate triggers, in my case I will be searching for "Recurrence"
Select the icon shown below


after that select Recurrence again as shown below


New window will open like below


Set in the parameters acc to your need, I will be setting Once a day
Now click on Next step, a window will open like below, where you can select actions


Now select variables, and select in "Initialize variable" like below


Now fill in the name of the variable and type like shown below


Now you may rename the action as well, as shown below


Now do the same for "To path" variable as shown below


Now add an action and 'SFTP' and select 'List files in folder', as shown below


you will see something like below


In my case I have already setup the SFP connection, but you can also setup like below


Fill in the connection name, host server address, username and password (click on disable SSH host key validation) if you are using username and password

Now save the connection and make it as default

Now click on the Folder, a lookup will come like below


Selected 'From path' from the variables, final should look like below


Now click on, New step and  search for 'For each' in control


Now select the 'body', as shown below


Rename the 'For each' to 'Move to each file' and Now the logic app should look like below



Now select an action inside the loop, now search for condition and select like shown below


Now condition action will be added, there you can select Name in the condition as shown below


expression should look like below


Now in the true side, search for SFTP and select "Copy file" as shown below


Now the copy file action should look like below


the 1st expression in the Destination file path is utcNow('yyyy')
and the 2nd expression in the Destination file path is utcNow('MM')

Now below that action add an action 'Delete file' as shown below


Now configure the Delete file action like below


Tada!!!