title: Download file from HTTPS url
body: <p>I am trying to download a zip file in SSIS script task using the following code below. However, I am getting the error: </p>
  
  <blockquote>
    <p>[] Error: The underlying connection was closed: An unexpected error
    occurred on a send.</p>
  </blockquote>
  
  <p>The file I am trying to download is: <a href="https://www.sam.gov/public-extracts/SAM-Public/SAM_Exclusions_Public_Extract_16229.ZIP" rel="nofollow">https://www.sam.gov/public-extracts/SAM-Public/SAM_Exclusions_Public_Extract_16229.ZIP</a></p>
  
  <p>Any help would be appreciated</p>
  
  <pre><code>public void Main()
  {      
      WebClient myWebClient;
      string RemoteURI;
      string LocalFileName;
      bool FireAgain = true;
  
      Variables vars = null;
      Dts.VariableDispenser.LockForRead("User::vSSOReportURL");
      Dts.VariableDispenser.LockForRead("User::vSSOLocalFileName");
      Dts.VariableDispenser.LockForWrite("User::vSSOReportURLIndicator");
      Dts.VariableDispenser.GetVariables(ref vars);
  
      try
      {
          // Ignore certificate warnings
          ServicePointManager.ServerCertificateValidationCallback = 
               new RemoteCertificateValidationCallback(delegate { return true; });
  
          // Initiate webclient download, use default credentials (current login)
          myWebClient = new WebClient();
          myWebClient.Credentials = CredentialCache.DefaultCredentials; 
  
          RemoteURI = vars["User::vSSOReportURL"].Value.ToString();
          LocalFileName = vars["User::vSSOLocalFileName"].Value.ToString();
  
  
          // Log provider notification 
          Dts.Events.FireInformation(0, String.Empty, String.Format("Downloading '{0}' from '{1}'", 
          LocalFileName, RemoteURI), String.Empty, 0, ref FireAgain);
  
          // Download the file 
          myWebClient.DownloadFile("https://www.sam.gov/public-extracts/SAM-Public/SAM_Exclusions_Public_Extract_16229.ZIP", @"c:\temp\SAM_Exclusions_Public_Extract_16229.ZIP");
  
          // Set report URL indicator, this is used to determine the http source of the 
          // download i.e. vSSOReportURL or vSSOReportURLRetry for the message which is 
          // written to the table
          vars["User::vSSOReportURLIndicator"].Value = 0;
  
          // Return success
          Dts.TaskResult = (int)ScriptResults.Success;
      }
  
      catch (Exception ex)
      {
          // Catch and handle error 
          Dts.Events.FireError(0, String.Empty, ex.Message, String.Empty, 0);
          Dts.TaskResult = (int)ScriptResults.Failure;
      }
  }
  </code></pre>