In SSIS 2005, I am using the FTP Task. I have a flow where when the package runs, it retrieves any files in a specific folder from FTP to a local folder.
Remote folder path is set by variable such as /root/abc/*abc.txt
The task works fine if there are files in that folder matching this criteria. If there are no files, the task fails with a file not found error!
How can I make SSIS not break the task in case this specific file not found error comes up simply becuase the remote folder had no matching files?
But, in case there is an error such as FTP server not able to login etc., then the task should throw the expected error.
Probably, you have found an answer to your question by now. Here is one possible way of achieving this.
Script Task
can be used to find the list of files present in an FTP folder path for a given pattern (say*.txt
). Below example shows how this can be done.Step-by-step process:
On the SSIS package, create an
FTP Connection
named FTP and also create 5 variables as shown in screenshot #1. VariableRemotePath
contains the FTP folder path;LocalPath
contains the folder where the files will be downloaed to;FilePattern
contains the file pattern to find the list of files to download from FTP server;FileName
will be populated by theForeach loop container
but to avoid FTP task design time error, it can be populated with / or theDelayValidation
property on the FTP Task can be set to True.On the SSIS package, place a
Script Task
,Foreach Loop container
andFTP Task
within theForeach Loop container
as shown in screenshots #2.Replace the
Main()
method within theScript Task
with the code under the Script Task Code section. Script Task will populate the variable ListOfFiles with the collection of files matching a given pattern. This example will first use the pattern *.txt, which yields no results and then later the pattern *.xls that will match few files on the FTP server.Configure the
Foreach Loop container
as shown in screenshots #3 and #4. This task will loop through the variable **ListOfFiles*. If there are no files, the FTP task inside the loop container will not execute. If there are files, the FTP task inside the loop container will execute for the task for the number of files found on the FTP server.Configure the
FTP Task
as shown in screenshots #5 and #6.Screenshot #7 shows sample package execution when no matching files are found for the pattern
*.txt
.Screenshot #8 shows the contents of the folder
C:\temp\
before execution of the package.Screenshot #9 shows sample package execution when matching files are found for the pattern
*.xls
.Screenshot #10 shows the contents of the FTP remote path
/Practice/Directory_New
.Screenshot #11 shows the contents of the folder
C:\temp\
after execution of the package.Screenshot #12 shows the package failure when provided with incorrect Remote path.
Screenshot #13 shows the error message related to the package failure.
Hope that helps.
Script Task Code:
C# code that can be used in
SSIS 2008 and above
.Include the
using
statement using System.Text.RegularExpressions;VB code that can be used in
SSIS 2005 and above
.Include the
Imports
statement Imports System.Text.RegularExpressionsScreenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
Screenshot #7:
Screenshot #8:
Screenshot #9:
Screenshot #10:
Screenshot #11:
Screenshot #12:
Screenshot #13: