posted on Wednesday, May 25, 2005 5:46 PM
by
ashvinis
SSIS: Downloading a file over HTTP
A question came up on an internal alias about how can one download a file over HTTP. Here's a script that does that, should be trivial to wrap it inside a task if you forsee doing this over and over again.
I can't get the colors to show up on the post, though.
Imports System.Net
Public Sub Main()
Dim myWebClient As WebClient
Dim remoteUri As String
Dim localFileName As String
Dim fireAgain As Boolean
Try
myWebClient = New WebClient()
' get the context from variables
remoteUri = CStr(Dts.Variables("RemoteUri").Value)
localFileName = CStr(Dts.Variables("LocalFileName").Value)
' tell the user what we're downloading where
Dts.Events.FireInformation(0, String.Empty, String.Format("Downloading '{0}' from '{1}'", localFileName, remoteUri), String.Empty, 0, fireAgain)
' do the actual download
myWebClient.DownloadFile(remoteUri, localFileName)
Dts.TaskResult = Dts.Results.Success
Catch ex As Exception
' post the error message we got back.
Dts.Events.FireError(0, String.Empty, ex.Message, String.Empty, 0)
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub