SQLTeam.com | Weblogs | Forums

Download .ZIP File from HTTP through SSIS


Hi Guys,

I want to download a .zip file from https site. The manual process is double click on the link and message pop up save the file hit SAVE and done.
I am in the process of automating this process Once a week through SSIS. Here is my SSIS Package looks like.

  1. Create Two Variables ( VarURL, VarDestinationFileSaved)

  2. Script Task
    Here is the code that I am using C# Code.
    public void Main()
    // TODO: Add your code here

         Variables varCollection = null;
         Dts.VariableDispenser.GetVariables(ref varCollection);
         System.Net.WebClient myWebClient = new System.Net.WebClient();
         string webResource = varCollection["User::VarURL"].Value.ToString();
         string fileName = varCollection["User::VarDestinationFileSaved"].Value.ToString() + webResource.Substring(webResource.LastIndexOf('/') + 1);
         myWebClient.DownloadFile(webResource, fileName);
     	Dts.TaskResult = (int)ScriptResults.Success;

However, I am getting Error.
" 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()"

I am not good in C#. Anyone, please advise me (it is urgent please). Thank You in advance.