SSIS : How to Download a file from HTTP location using SSIS
we can use Script task in SSIS to download the file from HTTP location.
we need to pass 3 variables to script task
1. FileURL
2. FileName
3.Destination --where the file needs to be placed.
Here is the complete script
'' Microsoft SQL Server Integration Services Script Task
'' Write scripts using Microsoft Visual Basic 2008.
'' The ScriptMain is the entry point class of the script.*/Imports System
Imports System.DataImports System.MathImports Microsoft.SqlServer.Dts.RuntimeImports System.Net Imports System.IOwe need to pass 3 variables to script task
1. FileURL
2. FileName
3.Destination --where the file needs to be placed.
Here is the complete script
'' Microsoft SQL Server Integration Services Script Task
'' Write scripts using Microsoft Visual Basic 2008.
'' The ScriptMain is the entry point class of the script.*/Imports System
<System.AddIn.AddIn(
"ScriptMain", Version:="1.0", Publisher:="", Description:="")> _<System.CLSCompliantAttribute(
False)> _Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResultsSuccess = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End EnumPublic Sub Main()
''This routine will try to fetch all files since the LastFetched date and now() for one single source */'' Fetch the package vars for this source */Dim sHttpFilepath As String = Dts.Variables("UnicastQualityURL").Value
Dim sDestPath As String = Dts.Variables("UnicastQualitySource").Value
Dim sFileName As String = Dts.Variables("UnicastQualityFilename").Value
Dim oWC As WebClient = New WebClient()
TryoWC.DownloadFile(sHttpFilepath, sDestPath & sFileName)
Catch ex As ExceptionSystem.IO.File.Delete(sDestPath & sFileName)
Dts.Events.FireWarning(
Nothing, "HTTP Conn", "File " + sFileName + " not present", Nothing, Nothing)
End Try
Dts.TaskResult = ScriptResults.Success
End SubEnd
Class
Comments
Post a Comment