Downloading file by script task over http

  • Do you use a proxy? You might have to add one to your code?

    The following has worked for me...

    Imports System

    Imports System.Data

    Imports System.Math

    Imports Microsoft.SqlServer.Dts.Runtime

    Imports System.Net

    Public Class ScriptMain

    Public Sub Main()

    Dim WebConnection As New WebClient()

    Dim proxyConnection As New WebProxy("http://proxy.server.com")

    Dim creds As New NetworkCredential("UserName", "Password")

    Try

    With WebConnection

    .Proxy = proxyConnection

    .BaseAddress = "https://www.myDomain.com/"

    .Credentials = creds

    End With

    Catch ex As Exception

    Dts.Events.FireError(0, "Problem connecting to website: ", ex.Message, "", 0)

    End Try

    Try

    With WebConnection

    .DownloadFile("https://www.myDomain.com/folder/", "myFileName.zip")

    End With

    Catch ex As Exception

    Dts.Events.FireError(0, "Problem downloading file: ", ex.Message, "", 0)

    End Try

    Dts.TaskResult = Dts.Results.Success

    End Sub

    End Class

    Kindest Regards,

    Frank Bazan

  • Hi Frank,

    How would your code look without the use of a proxy server?

    Thanks,

    Dave

  • Hi David,

    I'd try just removing the proxy declaration and method...

    Imports System

    Imports System.Data

    Imports System.Math

    Imports Microsoft.SqlServer.Dts.Runtime

    Imports System.Net

    Public Class ScriptMain

    Public Sub Main()

    Dim WebConnection As New WebClient()

    Dim creds As New NetworkCredential("UserName", "Password")

    Try

    With WebConnection

    .BaseAddress = "https://www.myDomain.com/"

    .Credentials = creds

    End With

    Catch ex As Exception

    Dts.Events.FireError(0, "Problem connecting to website: ", ex.Message, "", 0)

    End Try

    Try

    With WebConnection

    .DownloadFile("https://www.myDomain.com/folder/", "myFileName.zip")

    End With

    Catch ex As Exception

    Dts.Events.FireError(0, "Problem downloading file: ", ex.Message, "", 0)

    End Try

    Dts.TaskResult = Dts.Results.Success

    End Sub

    End Class

    Cheers

    Kindest Regards,

    Frank Bazan

  • Worked like a charm. Thanks, Frank!

  • Thanks for your reply. But my URL is different from yours like a path.

    http://abc.com/DataUniverse.aspx?SecurityTypeId=ST00000001

    I have created a C# program to download the file.

    thanks ervery one!

  • Hi I'm doing the same thing, download file from https. the webconnection part works but the downloadfile part doesn't.

    With WebConnection

    .DownloadFile("http://www.site.com", "file.zip")

    is file.zip the file on http or the filename to save as on my machine? and where do i specify where to download to? create a variable?

    also i need to compare all the files on https with the files on my local archive folder and then only download those files which are not in my local archive folder. how do i add that piece in the script task?

    Thanks!

Viewing 6 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply