Quantcast
Channel: Welcome To TechBrothersIT
Viewing all articles
Browse latest Browse all 1874

How to Download a File from FTP Site and Delete after Download in SSIS Package - SQL Server Integration Services(SSIS) Tutorial

$
0
0

Scenario:

In this video we will learn how to download a file from FTP Server Folder to Local Folder and then delete from the FTP Server Folder.

Items we will learn this video
  1. How to create SSIS Package from Scratch
  2. How to Create FTP Connection
  3. How to create variables to save Local Path, Remote Path and FileName
  4. How to use variables in Script Task to Download the file and then Delete after download if file exists
  5. How to use FTP Connection in Script Task in SSIS Package



VB.Net Script to download File from FTP Server and then Delete

PublicSub Main()

Dim StrFolderArrary AsString()
Dim StrFileArray AsString()
Dim fileName AsString
Dim RemoteDirectory AsString
Dim LocalFolderPath AsString

'Set Local Variable values by using SSIS Package variables
RemoteDirectory = Dts.Variables("User::RemoteDirectory").Value.ToString()
LocalFolderPath = Dts.Variables("User::LocalFolder").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

'Provide the Directory on which you are working on FTP Server


ftp.SetWorkingDirectory(RemoteDirectory)

'Get all the files and Folders List


ftp.GetListing(StrFolderArrary, StrFileArray)

'If there is no file in the folder, strFile Arry will contain nothing, so close the connection.

If StrFileArray IsNothingThen
ftp.Close()

'If Files are there, Loop through the StrFileArray arrary and download the file 
'and then delete

Else
ForEach fileName In StrFileArray

'Check if require file is there

If fileName = Dts.Variables("User::FileName").Value.ToString() Then

Dim DownloadFileNameArrary AsString()
DownloadFileNameArrary = {RemoteDirectory + "/" + fileName}

'Download the file

ftp.ReceiveFiles(DownloadFileNameArrary, LocalFolderPath, True, True)

'Delete the file

ftp.DeleteFiles(DownloadFileNameArrary)

EndIf
Next
ftp.Close()
EndIf
' Add your code here
'
Dts.TaskResult = ScriptResults.Success
EndSub



How to Download a File from FTP Server and then Delete It by using Script Task in SSIS Package

Viewing all articles
Browse latest Browse all 1874

Trending Articles