Scenario:
We need to download or remove the file from FTP Server. But let's say the file is not present. If we try to download or delete the file we will get an error as file is not available. How we can avoid this error in SSIS Package.What we will learn this in video
- How to run couple of test with FTP Task to Fail if File not exists in SSIS Package
- Create Variables to hole remote path, File Name , Local Folder paths in SSIS Package
- How to create FTP Connection Manager and use in Script Task
- How to create Flag variable in SSIS Package and update the value in Script task depending upon the availability of file on FTP Server
- How to use Precedence Constraint in SSIS Package to handle the flow of Tasks
PublicSub Main()
Dim StrFolderArrary AsString()
Dim StrFileArray AsString()
Dim fileName AsString
Dim RemoteDirectory AsString
RemoteDirectory = Dts.Variables("User::RemoteFolder").Value.ToString()
Dim cm As ConnectionManager = Dts.Connections("FTPConnection") 'FTP connection manager name
Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))
ftp.Connect() 'Connecting to FTP Server
ftp.SetWorkingDirectory(RemoteDirectory) 'Provide the Directory on which you are working on FTP Server
ftp.GetListing(StrFolderArrary, StrFileArray) 'Get all the files and Folders List
'If there is no file in the folder, strFile Arry will contain nothing, so close the connection.
If StrFileArray IsNothingThen
MessageBox.Show(Dts.Variables("User::Flag").Value.ToString())
ftp.Close()
Dts.Variables("User::Flag").Value = 0
'If Files are there, Loop through the StrFileArray arrary and insert into table
Else
ForEach fileName In StrFileArray
MessageBox.Show(fileName)
If fileName = Dts.Variables("User::FileName").Value.ToString() Then
Dts.Variables("User::Flag").Value = 1
MessageBox.Show(Dts.Variables("User::Flag").Value.ToString())
EndIf
Next
ftp.Close()
EndIf
' Add your code here
'
Dts.TaskResult = ScriptResults.Success
End Sub
How to Avoid FTP Task Error when No File Found on FTP Server in SSIS Package