I'm using SQL Server 2005, and creating ftp tasks within SSIS.
Sometimes there will be files to ftp over, sometimes not. If there are no files, I don't want the task nor the package to fail. I've changed the arrow going from the ftp task to the next to "completion", so the package runs through. I've changed the allowed number of errors to 4 (because there are 4 ftp tasks, and any of the 4 directories may or may not have files).
But, when I run the package from a job in agent, it marks the job as failing. Since this will be running every 15 minutes, I don't want a bunch of red x's in my job history, which will cause us to not see a problem when it really does occur.
How do I set the properties in the ftp task so that not finding files to ftp is not a failure? The operation I am using is "Send files".
Here is some more information: the files are on a server that I don't have any access through except ftp. And, I don't know the filenames ahead of time. The user can call them whatever they want. So I can't check for specific files, nor, I think, can I check at all. Except through using the ftp connection and tasks based upon that connection. The files are on a remote server, and I want to copy them over to my server, to get them from that remote server.
I can shell a command level ftp in a script task. Perhaps that is what I need to use instead of a ftp task. (I have changed to use the ftp command line, with a parameter file, called from a script task. It gives no errors when there are no files to get. I think this solution is going to work for me. I'm creating the parameter file dynamically, which means I don't need to have connection information in the plain text file, but rather can be stored in my configuration file, which is in a more secure location.)
I just had this issue, after reading some of the replies here, nothing really sorted out my problem and the solutions in here seem insane in terms of complexity.
My FTP task was failing since I did not allow overwriting files, lets say the job was kicked off twice in a row, the first pass will be fine, because some files are transferred over but will fail if a local file already exists.
My solution was simple:
I understand that you have found an answer to your question. This is for other users who might stumble upon this question. 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:
I don't have a packaged answer for you, but since no one else has posted anything yet...
You should be able to set a variable in an ActiveX script task and then use that to decide whether or not the FTP task should run. There is an example here that works with local paths. Hopefully you can adapt the concept (or if possible, map the FTP drive and do it that way).
You can redirect on failure, to another task that does nothing, ie a script that just returns true.
To do this, add the new script task, highlight your FTP task, a second green connector will appear, drag this to the script task, and then double click it. Select Failure on the Value drop down. Obviously, you'll then need to handle real failures in this script task to still display right in the Job history.
(I can't accept my own answer, but this was the solution that worked for me.)
It may not be the best solution, but this works.
I use a script task, and have a bunch of variables for the ftp connection information, and source and destination directories. (Because, we'll be changing the server this is run on, and it will be easier to change in a config package.)
I create a text file on the fly, and write the ftp commands to it:
Then, after giving it enough time to really close, I start a process to do the ftp command:
Then, after giving it some more time for the ftp process to run, I delete the temporary ftp file (that has connection information in it!).
If files don't exist in the source directory (the variable has the \\drive\dir\*.* mapping), then there is no error. If some other error happens, the task still fails, as it should.
I'm new to SSIS, and this may be a kludge. But it works for now. I guess I asked for the best way, and I'll certainly not claim that this is it.
As I pointed out, I have no way of knowing what the files are named, or even if there are any files there at all. If they are there, I want to get them.
1) Set the FTP Task property ForceExecutionResult = Success
2) Add this code to FTP Task OnError event handler.