Home > OS >  How to copy particular files from sFTP source location if the files are not already present in sFTP
How to copy particular files from sFTP source location if the files are not already present in sFTP

Time:03-16

I want to filter source folder for files have name starting with 'File'. Then I want to check if those files are already present in sink folder. If not present then copy else skip.

Picture 1 -This is the initial picture which contains files in source and sink This is the initial picture which contains files in source and sink

Picture 2 - This is the desired output where only those files are copied which were not present in Sink (except junk files) This is the desired output where only those files are copied which were not present in Sink (except junk files)

Picture 3 - This is how I tried. There are IF & copyData activity in ForEach, But I am getting error in copyData activity. This is how I tried. There are IF & copyData activity in ForEach, But I am getting error in copyData activity.

CodePudding user response:

I have reproed in my local environment as shown below.

  1. Get sink files list where filename starts with ‘file’ using Get Metadata activity.

enter image description here

The output of Get Metadata1:

enter image description here

  1. Create an array variable to store the list of sink files.

enter image description here

  1. Convert Get Metadata activity (Get sink files) output to the array by using ForEach activity and append each filename to an array variable.

@activity('Get Sink Files').output.childItems

enter image description here

Add append variable activity inside ForEach activity.

enter image description here

  1. Now get the list of source files using another Get Metadata activity in the pipeline.

enter image description here

The output of Get metadata2:

enter image description here

  1. Connect Get Metadata activity2 (Get Source files) output and ForEach activity to another ForEach activity2.

@activity('Get Source Files').output.childItems

enter image description here

  1. Add If Condition activity inside ForEach2 activity. Add expression to check the current item (each source file) contains in the array variable.

@contains(variables('sink_files_list'),item().name)

enter image description here

  1. When false add copy activity to copy source file to sink.

Source:

enter image description here

Sink:

enter image description here

CodePudding user response:

Similar one. when try to add dynamic file name (linked server) in azure data factory V2 error encountered

Try @string() or @{} in dynamic content on fileName.

  • Related