c# - 无法从免费 Azure 应用服务连接到远程 SFTP 服务器
问题描述
我有一个在本地运行良好的 Asp.Net Core 网站我能够连接到 SFTP 服务器并获取文件。但是,一旦我部署到 Azure 应用服务,尝试建立连接就会超时。
我得到的例外是
2019-09-03 10:37:28.7942||ERROR|ExclusiveCard.Services.SFTPProvider|Renci.SshNet.Common.SshOperationTimeoutException: Session operation has timed out
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
at ExclusiveCard.Services.SFTPProvider.TestConnection() in SFTPProvider.cs:line 237 Renci.SshNet.Common.SshOperationTimeoutException: Session operation has timed out
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
我使用的代码是
SftpClient sftpClient = null;
try
{
sftpClient = new SftpClient("servaer", 2222, "ExclusiveDev", "password");
}
catch (Renci.SshNet.Common.SshOperationTimeoutException ex)
{
Console.WriteLine(ex.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
我使用了 Package Renci.SshNet.Async version="1.4.0。此代码在本地运行良好,但在部署时在 Azure App Service 上失败。
非常感谢任何帮助。谢谢。
解决方案
听起来您已将 ASP.NET Core 应用程序部署到 Windows 上的 Azure 应用程序服务,并且它试图从 Windows 上的 Azure 应用程序服务连接远程 SFTP 服务器。
所以我确信它永远不会像你预期的那样在 Windows 系统的 Azure App Service 上正常工作,因为Use of Raw Sockets
Azure Web App 沙箱有一个网络限制来限制套接字连接的建立,如下所示。
所以我建议您可以尝试重新构建您的应用程序以将其部署到Linux 上的 Azure 应用服务。
推荐阅读
- android - 如何使用 android 中的意图打开内部存储器中的屏幕截图文件夹?
- microsoft-graph-api - 有没有办法使用图形API获取共享点office365的回收站项目?
- reactjs - 哪种酶适配器适用于 React 17?
- html - 浏览器是如何决定这些表格列的宽度的?
- javascript - Ajax 函数在模态关闭和打开时运行多次
- python - 如何将值列表作为多个 Python 请求参数动态传递?
- c++ - C ++中队列的最大大小限制是多少/决定大小限制或溢出限制的所有因素是什么?
- javascript - 如何用对象值替换字符串
- python - 如何在 python 中的 DynamoDB 查询中使用限制数据?
- python - How can I find a word ending with "n't" before a number using Regex?