SQLTeam.com | Weblogs | Forums

Download the file from Web (Automate Process)


Hi Guys,

I need urgent help.
I am working on automating the process to download the file from Web once a month. I am using SSIS for this.
First Step:- I created "HTTP Connection Manager Editor" on server URL: http://download.com/Account/Download/?file=may2016_z5c6c_csv.zip&username=USERNAME&password=PASSWORD (AS AN EXAMPLE) and Test Connection "Test Connection Succeeded"
Second Step:- Drag and drop "Script Task Editor" and used ScriptLanguage "Microsoft Visual Basic 2012" Here is the code that I am using
Public Sub Main()
' ' Get the unmanaged connection object, from the connection manager called "HTTP Connection Manager"
Dim nativeObject As Object = Dts.Connections("HTTP").AcquireConnection(Nothing)

    ' Create a new HTTP client connection
    Dim connection As New HttpClientConnection(nativeObject)

    ' Download the file #1

' Save the file from the connection manager to the local path specified
Dim filename As String = "C:\wgetfolder\DOWNLOAD.ZIP"
connection.DownloadFile(filename, True)

    Dts.TaskResult = ScriptResults.Success
End Sub

Here is the error that I am getting
"at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()"

Please advise how can I fix this error.

Thank You.