Azure functions 使用应用程序服务计划通过Azure功能应用程序出现FTP服务器连接问题
我有一个Azure功能应用程序,它使用下面的代码连接到FTP服务器。但是,连接到服务器时出错 只有当应用程序托管在Azure功能上,并且在我的本地计算机上本地工作时,才会发生此错误 错误是随机的和间歇性的,一旦发生,错误将继续。但有时,即使发生错误,它也会连接 例如,我设置了一个测试,每分钟运行一次,持续一小时,它在开始时工作一段时间,然后连接没有建立,之后所有后续请求都失败了 FluentFTP包:27.1.0 Azure功能应用程序使用应用程序服务计划 请在下面的代码后查找异常Azure functions 使用应用程序服务计划通过Azure功能应用程序出现FTP服务器连接问题,azure-functions,ftpwebrequest,azure-functions-runtime,azure-functions-core-tools,fluentftp,Azure Functions,Ftpwebrequest,Azure Functions Runtime,Azure Functions Core Tools,Fluentftp,我有一个Azure功能应用程序,它使用下面的代码连接到FTP服务器。但是,连接到服务器时出错 只有当应用程序托管在Azure功能上,并且在我的本地计算机上本地工作时,才会发生此错误 错误是随机的和间歇性的,一旦发生,错误将继续。但有时,即使发生错误,它也会连接 例如,我设置了一个测试,每分钟运行一次,持续一小时,它在开始时工作一段时间,然后连接没有建立,之后所有后续请求都失败了 FluentFTP包:27.1.0 Azure功能应用程序使用应用程序服务计划 请在下面的代码后查找异常 public
public async Task<byte[]> ReadAllBytesAsync()
{
byte[] content = new byte[0];
try
{
using (FluentFTP.FtpClient client = GetFtpClient())
{
client.Connect();
if (!client.FileExists(_configSetting.FtpServer.FilePath))
{
throw new Exception($"{_configSetting.FtpServer.FilePath} doesn't exist");
}
content = await client.DownloadAsync(_configSetting.FtpServer.FilePath, CancellationToken.None);
client.Disconnect();
}
}
catch (Exception e)
{
throw new Exception($"Error", e);
}
return content;
}
public void DeleteFile(string filePath)
{
try
{
using (FluentFTP.FtpClient client = GetFtpClient())
{
client.Connect();
if ( client.FileExists(filePath))
{
client.DeleteFile(filePath);
}
client.Disconnect();
}
}
catch (Exception e)
{
throw new Exception(
$"Error",
e);
}
}
private FluentFTP.FtpClient GetFtpClient()
{
FluentFTP.FtpClient client = new FluentFTP.FtpClient(_configSetting.FtpServer.Host,
_configSetting.FtpServer.Port,
_configSetting.FtpServer.Username,
_configSetting.FtpServer.Password)
{
EncryptionMode = FtpEncryptionMode.Explicit,
SslProtocols = SslProtocols.Tls
};
client.ValidateCertificate += OnValidateCertificate;
return client;
}
private void OnValidateCertificate(FluentFTP.FtpClient control, FtpSslValidationEventArgs e)
{
//accept remote certificate without validation
e.Accept = true;
}
公共异步任务readAllByteAsync()
{
字节[]内容=新字节[0];
尝试
{
使用(FluentFTP.FtpClient client=GetFtpClient())
{
client.Connect();
如果(!client.FileExists(_configSetting.FtpServer.FilePath))
{
抛出新异常($“{u configSetting.FtpServer.FilePath}不存在”);
}
content=wait client.downloadsync(_configSetting.FtpServer.FilePath,CancellationToken.None);
client.Disconnect();
}
}
捕获(例外e)
{
抛出新异常($“Error”,e);
}
返回内容;
}
公共void DeleteFile(字符串文件路径)
{
尝试
{
使用(FluentFTP.FtpClient client=GetFtpClient())
{
client.Connect();
if(client.FileExists(filePath))
{
client.DeleteFile(filePath);
}
client.Disconnect();
}
}
捕获(例外e)
{
抛出新异常(
$“错误”,
e) );
}
}
private FluentFTP.FtpClient GetFtpClient()
{
FluentFTP.FtpClient client=新的FluentFTP.FtpClient(_configSetting.FtpServer.Host,
_configSetting.FtpServer.Port,
_configSetting.FtpServer.Username,
_configSetting.FtpServer.Password)
{
EncryptionMode=FtpEncryptionMode.Explicit,
SslProtocols=SslProtocols.Tls
};
client.ValidateCertificate+=OnValidateCertificate;
返回客户;
}
私有void OnValidateCertificate(FluentFTP.FtpClient control,FtpSslValidationEventArgs e)
{
//接受未经验证的远程证书
e、 接受=真;
}
错误消息是
尝试连接时超时
或
连接尝试失败,因为连接方未连接
在一段时间后或建立连接后正确响应
失败,因为连接的主机未能响应
下面是堆栈策略:
[{“severityLevel”:“Error”,“parsedStack”:[{“assembly”:“MyApp.FtpClient,Version=1.0.0,Culture=neutral,PublicKeyToken=null”,“method”:“MyApp.FtpClient.FtpClientWrapper+d_3.MoveNext”,“level”:0,“line”:50,“fileName”:“C:\\ u Repos\MyApp\src\MyApp.FtpClient\FtpClientWrapper.cs”,{“assembly”:“System.Private.CoreLib,版本=4.0.0,区域性=中性,PublicKeyToken=7cec85d7bea7798e”,“方法”:“System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw”,“级别”:1,“行”:0},{“程序集”:“System.Private.CoreLib,版本=4.0.0.0,区域性=中性,PublicKeyToken=7cec85d7bea7798e”,“方法”:”System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess,“级别”:2,“行”:0},{“程序集”:“System.Private.CoreLib,版本=4.0.0.0,区域性=中性,PublicKeyToken=7cec85d7bea7798e”,“方法”:“System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification”,“级别”:3,“行”:0},{“程序集”:MyApp.AppService,版本=1.0.0.0,区域性=neutral,PublicKeyService=null,“方法”:“MyApp.AppService.Services.DeviceService+d.MoveNext”,“级别”:4,“行”:95,“文件名”:“C:\\\U Repos\MyApp\src\MyApp.AppService\Services\DeviceService.cs”},{“程序集”:“System.Private.CoreLib,版本=4.0.0.0,区域性=neutral,PublicKeyToken=7cec85d7bea7798e”,“方法”:System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw,“level”:5,“line”:0},{“assembly”:“System.Private.CoreLib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e”,“method”:“System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess”,“level”:6,“line”:0},{“assembly”:”System.Private.CoreLib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e,“方法”:“System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification”,“级别”:7,“行”:0},{“程序集”:“MyApp.AppService,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”,“方法”:MyApp.AppService.Services.DeviceService+d_8.MoveNext,“级别”:8,“行”:71,“文件名”:“C:\\u Repos\MyApp\src\MyApp.AppService\Services\DeviceService.cs”},{“程序集”:“System.Private.CoreLib,版本=4.0.0.0,区域性=中性,PublicKeyToken=7cec85d7bea7798e”,“方法”:“System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw”,“级别”:9,“行”:0},{”程序集“:”System.Private.CoreLib,版本=4.0.0,区域性=中性,PublicKeyToken=7cec85d7bea7798e”,“方法“:”System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess”,“级别”:10,“行”:0},{”程序集“:”System.Private.CoreLib,版本=4.0.0.0,区域性=中性,PublicKeyToken=7cec85d7bea7798e”,“方法“:”System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification,“级别”:11,“行”:0},{“程序集”:“MyApp.AppService,版本=1.0.0.0,区域性=中性,PublicKeyToken=null”,“方法”:“MyApp.AppService.Services.DeviceService+d_7.MoveNext”,“级别”:12,“行”:47,“文件名”:C:\\U Repos\MyApp\src\MyApp.AppService\Services\DeviceService.cs“},{“assembly”:“System.Private.CoreLib,Version=4.0。