简体   繁体   English

无法通过免费的Azure应用服务连接到远程SFTP服务器

[英]Unable to connect to a remote SFTP server from a Free Azure app service

I have a Asp.Net Core website running fine locally I am able to connect to an SFTP server and get files. 我有一个在本地运行良好的Asp.Net Core网站,我能够连接到SFTP服务器并获取文件。 But once I deploy to Azure app service it will just timeout trying to establish a connection. 但是,一旦我部署到Azure应用服务,它将试图建立连接只是超时。

The exception I get is 我得到的例外是

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()

Code I have used is 我使用的代码是

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());
    }

I have used Package Renci.SshNet.Async version="1.4.0. This code works perfectly fine locally but fails on the Azure App Service when deployed. 我使用过程序包Renci.SshNet.Async version =“ 1.4.0。此代码在本地完全正常,但是在部署时在Azure App Service上失败。

Any help much appreciated. 任何帮助,不胜感激。 Thanks. 谢谢。

It sounds like you have deployed your ASP.NET Core app to Azure App Service on Windows, and it was trying to connect a remote SFTP server from Azure App Service on Windows. 听起来您已经将ASP.NET Core应用程序部署到Windows上的Azure App Service,并且它试图从Windows上的Azure App Service连接远程SFTP服务器。

So I'm sure that it will never work fine on Azure App Service of Windows system as you expected, because there is a networking restriction Use of Raw Sockets of Azure Web App sandbox to limit the socket connection establish, as below. 因此,我确定它永远不会在Windows系统的Azure App Service上正常工作,因为存在网络限制,如下所示, Use of Raw Sockets Azure Web App沙盒Use of Raw Sockets来限制套接字连接的建立。

在此处输入图片说明

So I suggest you can try to rebuild your app to deploy it to Azure App Service on Linux . 因此,我建议您可以尝试重建您的应用程序,以将其部署到Linux上的Azure App Service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM