magento 从http下载SSIS-错误:从服务器取得的SSL凭证回应无效

7gs2gvoe  于 2022-11-12  发布在  其他
关注(0)|答案(2)|浏览(131)

我创建了一个SSIS包,它使用C#脚本从HTTPS URL下载CSV文件。从Visual Studio执行时一切正常。
但是,当我建立SQL Agent作业时,封装会失败。如果我直接从SQL Server执行.dtsx档案,封装也会失败。
错误为
“下载失败:从服务器获取的SSL证书响应无效。无法处理请求”
我已测试从SQL服务器打开URL,并可以查看文件。我还在C#脚本中添加了代码以忽略证书错误,但这似乎没有任何影响。我还在连接管理器中输入了托管CSV的服务器的登录凭据,但这也没有帮助。
CSV是通过Magento数据源生成的。在网站上,所有内容都被重定向到HTTPS。
我在这里迷路了,所以希望有人能好心地帮助我。
下面是C#脚本的片段:

public void Main()
    {
        // TODO: Add your code here
        try
        {

            // Ignore certificate warnings
            ServicePointManager.ServerCertificateValidationCallback =
                 new RemoteCertificateValidationCallback(delegate { return true; });

            // Disable server certificate validation.
            //ServicePointManager
            //    .ServerCertificateValidationCallback +=
            //    (sender, cert, chain, sslPolicyErrors) => true;
            //ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => true;

            //System.Net.ServicePointManager.ServerCertificateValidationCallback =
            //delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            //{ return true; };

            // Logging start of download
            bool fireAgain = true;
            Dts.Events.FireInformation(0, "Download File", "Start downloading " + Dts.Connections["TEST"].ConnectionString, string.Empty, 0, ref fireAgain);

            // Get your newly added HTTP Connection Manager
            Object mySSISConnection = Dts.Connections["TEST"].AcquireConnection(null);

            // Create a new connection
            HttpClientConnection myConnection = new HttpClientConnection(mySSISConnection);

            // Download file and use the Flat File Connectionstring (D:\SourceFiles\Products.csv)
            // to save the file (and replace the existing file)                
            String filename = Dts.Variables["varFullPathScript"].Value.ToString();
            myConnection.DownloadFile(filename, true);

            // Logging end of download
            Dts.Events.FireInformation(0, "Download File", "Finished downloading" , string.Empty, 0, ref fireAgain);

            // Quit Script Task succesful
            Dts.TaskResult = (int)ScriptResults.Success;
        }
        catch (Exception ex)
        {
            // Logging why download failed
            Dts.Events.FireError(0, "Download File", "Download failed: " + ex.Message, string.Empty, 0);

            // Quit Script Task unsuccesful
            Dts.TaskResult = (int)ScriptResults.Failure;
        }

        Dts.TaskResult = (int)ScriptResults.Success;
    }
pcww981p

pcww981p1#

经过一番努力,我想我应该尝试一些简单的方法,即使用不同的方法来下载文件。我使用了一个webclient类,而不是HTTP连接管理器。这似乎已经工作!

WebClient webClient = new WebClient();
            //webClient.Credentials = new NetworkCredential("username", "PW", "domain"); //don't really need this unless URL requires auth
            webClient.DownloadFile(url, filename);
js5cn81o

js5cn81o2#

@乔纳森C -首先,谢谢你的想法,我也有同样的问题,你救了我的一天,但是

  1. TLS 1.0现在默认为禁用,因此我看到了 “底层连接已关闭:在调用System.Net.ServicePointManager.SecurityProtocol=System.Net.SecurityProtocolType.Tls12;之前添加此字符串之前,在发送” 异常时发生意外错误
    1.在这种情况下,我建议使用using关键字
    所以在我的案例中,最后的结果是
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
using (var webClient = new WebClient())
{
    webClient.DownloadFile(@"https://url", @"C:\file");
}

相关问题