Google 驱动器 Api - 复制多个文件后出错 .NET - 远程主机取消连接
Google Drive Api - Error after copying multiple files .NET - Cancel connection by remote host
下面的控制台应用程序 return 复制许多文件后出现异常。我想知道在 .NET 中使用 Google 驱动器 api 复制和创建文件夹的确切限制。遵循内部异常:"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);
}
}
}
Print_Error
感谢您的帮助!我意识到我们的 SonicWall 防火墙阻止了一些请求。将 (Sonicwall) 设置为不阻止我们的请求后,问题就解决了。
我在这里附上了完整的错误。
Print Error
下面的控制台应用程序 return 复制许多文件后出现异常。我想知道在 .NET 中使用 Google 驱动器 api 复制和创建文件夹的确切限制。遵循内部异常:"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);
}
}
}
Print_Error
感谢您的帮助!我意识到我们的 SonicWall 防火墙阻止了一些请求。将 (Sonicwall) 设置为不阻止我们的请求后,问题就解决了。 我在这里附上了完整的错误。
Print Error