取消远程主机的连接

取消远程主机的连接

本文介绍了Google云端硬盘Api-复制多个文件.NET后出现错误-取消远程主机的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的控制台应用程序在复制许多文件后返回异常.我想知道使用.NET中的Google驱动器api复制和创建文件夹的确切限制.遵循内部异常:无法从传输连接中读取数据:被远程主机强制取消了现有连接".

Console application below return exception after copying many files. I'd like to know the exactly limit of copying and creating folders with Google drive api in .NET. Follow the Inner Exception: "Unable to read data from the transport connection: Was Forced to cancel the exist connection by remote host".

static void Main(string[] args)
    {
        if (Debugger.IsAttached)
            CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US");
        string[] Scopes = { DriveService.Scope.DriveReadonly, DriveService.Scope.DriveFile };
        ServiceAccountCredential credential;
        using (var stream =
                        new FileStream("key.json", FileMode.Open, FileAccess.Read))
        {
            credential = GoogleCredential.FromStream(stream)
                                 .CreateScoped(Scopes)
                                 .UnderlyingCredential as ServiceAccountCredential;
        }
        // Create Drive API service.
        var service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Test App",
        });
        Google.Apis.Drive.v3.Data.File copiedFile = new Google.Apis.Drive.v3.Data.File();
        for (int i = 0; i < 50; i++)
        {
            copiedFile.Name = "";
            copiedFile.Parents = new List<string> { "1I6eCYECR8lfpWP6wFDWeYkTsUMC6jKie" };
            try
            {
                var lFile = service.Files.Copy(copiedFile, "157cV64pH6Jdpm8SER1MQStPhnl01XHI65AsfPwSeTqw").Execute();
                Console.WriteLine("File " + (i+1).ToString() + " copied.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error = " + e.InnerException.Message);
            }
        }
    }

打印错误

推荐答案

感谢您的帮助!我已经意识到我们的SonicWall防火墙阻止了一些请求.将(Sonicwall)设置为不阻止我们的请求后,此问题已解决. 我在这里附上了完整的错误.

Thanks for helping! I've realized that our SonicWall firewall was blocking some requests. After set (Sonicwall) to not block our request, the issue was resolved. I have attached the full error here.

打印错误

这篇关于Google云端硬盘Api-复制多个文件.NET后出现错误-取消远程主机的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 17:44