Creating a File in Script

  • Hi all,

    I am attempting to download zip files from a particular website and am having issues withDim mySSISWebClient As WebClient = New WebClient()

    ' Download file and use the Flat File Connectionstring (D:\SourceFiles\Products.csv)

    ' to save the file (and replace the existing file)

    mySSISWebClient.DownloadFile(hC, Dts.Connections(Dts.Variables("User::SaveFile").Value.ToString).ConnectionString)which comes from "http://microsoft-ssis.blogspot.ca/2011/05/download-source-file-from-website-with.html". There are no files in the SaveFile path which is a UNC path. I keep getting the error:

    Error: 0xC001000E at DownloadHttpPackage: The connection "\\****-*****-**\FA-BUSANALYEC\EconomicDBTemp\DownloadedCSVs\http://www20.statcan.gc.ca/tables-tableaux/cansim/csv/00260001-eng.zip" is not found.

    The file doesn't exist and shouldn't until I download the file from the statcan url. All I want for this to accomplish is to get the zip file from the website and dump it in \\****-*****-**\FA-BUSANALYEC\EconomicDBTemp\DownloadedCSVs\ with its URL as its name. By the way, "\\****-*****-**\FA-BUSANALYEC\EconomicDBTemp\DownloadedCSVs\http://www20.statcan.gc.ca/tables-tableaux/cansim/csv/00260001-eng.zip" is an expression in the variable SaveFile and it looks like

    @[User::SaveFile] + @[User::httpConnection]

    Any ideas what I am doing wrong?

    Regards:
    Mordred
    Keep on Coding in the Free World

  • Alright, I am at a point now where this particular process completes (ie goes green) but all the files that are being downloaded are not there. The output window shows

    Information: 0x0 at Download_StatsCan_data, Download File: Finished downloading \\EWPG-SERVICE-60\FA-BUSANALYEC\EconomicDBTemp\DownloadedCSVsInformation: 0x0 at Download_StatsCan_data, Download File: Start downloading http://www20.statcan.gc.ca/tables-tableaux/cansim/csv/02820025-eng.zip

    Information: 0x0 at Download_StatsCan_data, Download File: Finished downloading \\EWPG-SERVICE-60\FA-BUSANALYEC\EconomicDBTemp\DownloadedCSVsInformation: 0x0 at Download_StatsCan_data, Download File: Start downloading http://www20.statcan.gc.ca/tables-tableaux/cansim/csv/02820026-eng.zip

    So there is a start and finish for each zip file but when I go to the folder that is supposed to keep these files, it is completely empty:sick:. I've changed the code a bit to allow for my webclient connection variable as well as my UNC path. It goes a little like:Try

    ' Logging start of download

    Dim fireAgain As Boolean = True

    Dts.Events.FireInformation(0, "Download File", "Start downloading " + Dts.Variables("User::httpConnection").Value.ToString(), String.Empty, 0, fireAgain)

    ' Create a webclient to download a file

    Dim mySSISWebClient As WebClient = New WebClient()

    ' Download file and use the Flat File Connectionstring (D:\SourceFiles\Products.csv)

    ' to save the file (and replace the existing file)

    mySSISWebClient.DownloadFile(Dts.Variables("User::httpConnection").Value.ToString(), Dts.Variables("User::SaveFile").EvaluateAsExpression())

    ' Logging end of download

    Dts.Events.FireInformation(0, "Download File", "Finished downloading " + Dts.Variables("User::SaveFile").Value.ToString(), String.Empty, 0, fireAgain)

    ' Quit Script Task succesful

    Dts.TaskResult = ScriptResults.Success

    Catch ex As Exception

    ' Logging why download failed

    Dts.Events.FireError(0, "Download File", "Download failed: " + ex.Message, String.Empty, 0)

    ' Quit Script Task unsuccesful

    Dts.TaskResult = ScriptResults.Failure

    End TryThe only way I could get this to run without error was to use the EvaluateAsExpression() like:mySSISWebClient.DownloadFile(Dts.Variables("User::httpConnection").Value.ToString(), Dts.Variables("User::SaveFile").EvaluateAsExpression())I'm completely at a loss right now and am working feverishly (literally as I am sick) to understand this and fix it but I feel like I am hitting a brick wall.

    Regards:
    Mordred
    Keep on Coding in the Free World

  • I figured this one out with some help. The following Try Catch worked to download 312 different zip files from our source.Try

    ' Logging start of download

    Dim fireAgain As Boolean = True

    Dts.Events.FireInformation(0, "Download File", "Start downloading " + Dts.Variables("User::httpConnection").Value.ToString(), String.Empty, 0, fireAgain)

    ' Create a webclient to download a file

    Dim mySSISWebClient As WebClient = New WebClient()

    ' Download file and use the Flat File Connectionstring (D:\SourceFiles\Products.csv)

    ' to save the file (and replace the existing file)

    mySSISWebClient.DownloadFile(Dts.Variables("User::httpConnection").Value.ToString, "\\****-*******-**\FA-BUSANALYEC\EconomicDBTemp\DownloadedCSVs\" + Dts.Variables("User::fileName").Value.ToString + ".zip")

    ' Logging end of download

    Dts.Events.FireInformation(0, "Download File", "Finished downloading " + Dts.Variables("User::SaveFile").Value.ToString(), String.Empty, 0, fireAgain)

    ' Quit Script Task succesful

    Dts.TaskResult = ScriptResults.Success

    Catch ex As Exception

    ' Logging why download failed

    Dts.Events.FireError(0, "Download File", "Download failed: " + ex.Message, String.Empty, 0)

    ' Quit Script Task unsuccesful

    Dts.TaskResult = ScriptResults.Failure

    End TryAll along it was because I wasn't creating a file name.zip for the files. Now that that is done, it's on to the next step! Woohoo! 🙂

    Regards:
    Mordred
    Keep on Coding in the Free World

Viewing 3 posts - 1 through 2 (of 2 total)

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