Revisited: Delete From FTP using Azure Data Factory

Due to the demand I have decided to revisit the solution that deletes files from FTP from within a Data Factory pipeline. I believe this approach is a much cleaner design. It is also easier to debug and control.

First make sure, you have read my article on setting up a Key Vault. It is crucial knownledge, as you are going to store FTP credentials there. Set it up and create two secrets – one for login and one for password. If you wish, you may also store your IP address.

Next, create a new Azure Function:

image

 

Make sure to pick v2:

image

Next paste the code into the solution:

 

Notice, that Login and Password are taken from the Key Vault:

 

Secret URLs are retrieved from Environmental variables that you can find in application settings:

image

 

Under applications settings:

image

 

Then, next step is to publish you function. You can do it from within Visual Studio by right-clicking on the project:

image

In there pick the Azure Function that you want to publish to, or alternatively create a new one. Remember to register you app in Azure Active Directory and add it in access policies in your Key Vault.

After publishing, navigate to Azure Portal and test your function. It expects JSON in this format:

 

 

If it does not work, you can debug it now.

Next step is calling a POST request from Data Factory. To do it, you will use a web activity. However, beforehand you have to copy function URL. To get it navigate to main function page and click </> Get Function URL.

image

 

Copy the function from the URL filed:

image

 

You are ready to go to your ADF pipeline and create a web activity:

image

 

Next you should specify the URL (that you have just copied) and JSON in body with Path and IP – you can even try to set up some dynamic content here:

image

And that is it! Now you can trigger the function and see if it works.

Leave a Reply

Your email address will not be published. Required fields are marked *