【发布时间】:2023-01-18 22:01:04
【问题描述】:
我面临一个问题,我在尝试连接 sfp 服务器时收到间歇性错误消息“远程主机强行关闭现有连接”。我正在尝试在 azure 函数应用程序中连接 sftp。我相信在存在连接问题时会发生此错误。为了处理这个问题,我需要实施重试逻辑以防万一发生此类错误,并以指定的延迟重复连接 sftp 服务器,直到达到配置的最大重试次数。我相信功能应用程序允许的最长执行时间是 5 分钟(需要从 azure 专家那里听到)。任何人都可以帮助我如何在 c# 中实现此重试功能。我正在使用 Renci.SshNet nuget 包来管理 sftp
using (var _sftpCn = new SftpClient(host, port, userName, password))
{
_sftpCn.Connect();//error happens on this line:"An existing connection was forcibly closed by the remote host"
log.LogInformation("Successful");
byte[] byteArray = Encoding.UTF8.GetBytes(datacontent);
sftpCl.WriteAllBytes("{remotePath}", byteArray);
log.LogInformation("Sent successfully");
_sftpCn.Disconnect();
}
【问题讨论】:
-
波莉也许可以在这里帮助你 github.com/App-vNext/Polly/wiki/Retry
标签: c# azure azure-functions sftp retry-logic