I am using following code to connect SFTP. It is working fine on my local system. but getting failed on Azure VM and giving exception "An existing connection was forcibly closed by the remote host".
I have already opened TCP 22 port as an outbound for that VM.
using (Renci.SshNet.SftpClient client = new Renci.SshNet.SftpClient(host, port, user, password))
{
try
{
client.Connect();
if (client.IsConnected)
{
Response.Write("OA Connected.");
}
// var f = client.ListDirectory("");
}
catch (Renci.SshNet.Common.SshAuthenticationException ae)
{
Response.Write("Exception while connecting to OA (SSH): " + Convert.ToString(ae.Message));
}
catch (Exception ex)
{
Response.Write("Exception while connecting to OA: " + Convert.ToString(ex.Message));
}
return new EmptyResult();
}
Any assistance would be much appreciated. Let me know if you need additional information.
If you have enabled port 22 on the “Networking” tab from the Azure portal, check if you have
enabled port 22 through Windows firewall (using the
control panel section from your virtual machine).
By default, the SFTP port is 22. If you have modified it yourself, you need to set it according to the actual port.
If your virtual machine is under a load balancer, you should:
Enable port 22 on the Windows firewall.
Use “Inbound NAT rules” tabs from your load balancer settings page through
Azure web portal. From there, add a rule to enable port 22 and redirect queries to your virtual machine
Best Regards,
YihuiSun
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I am not using Load Balancer for now. Will I need to use one? Can you please let me know steps to enable for outbound SFTP calls by adding load balancer settings?
Thank you for your response. I tried it, unfortunately it did not work.
I would like to provide additional information - When I try same connection from FileZilla, it does not work there as well and throws following error:
Status: Connecting to ftp.officeally.com... Response: fzSftp started, protocol_version=9 Command: open "XXXX@ftp.officeally.com" 22 Error: FATAL ERROR: Network error: Software caused connection abort Error: Could not connect to server
I have configured couple of web sites on same VM and they are working fine. So if I am not wrong, DNS is fine. I can also jump on Skype to connect and show you, if you have a moment now. I would really appreciate your help. Thank you!
Member
44 Points
145 Posts
Renci.SshNet.SftpClient getting failed on Azure VM
Aug 06, 2020 07:36 AM|sukhdeep_kambo|LINK
Hi Folks,
I am using following code to connect SFTP. It is working fine on my local system. but getting failed on Azure VM and giving exception "An existing connection was forcibly closed by the remote host".
I have already opened TCP 22 port as an outbound for that VM.
Any assistance would be much appreciated. Let me know if you need additional information.
Thank you!
Contributor
2690 Points
774 Posts
Re: Renci.SshNet.SftpClient getting failed on Azure VM
Aug 07, 2020 07:30 AM|YihuiSun|LINK
Hi Sukhdeep,
Best Regards,
YihuiSun
Member
44 Points
145 Posts
Re: Renci.SshNet.SftpClient getting failed on Azure VM
Aug 11, 2020 01:30 PM|sukhdeep_kambo|LINK
Hi YihuiSun,
Thank you for your response.
I am not using Load Balancer for now. Will I need to use one? Can you please let me know steps to enable for outbound SFTP calls by adding load balancer settings?
Thank you!
All-Star
58144 Points
15646 Posts
Re: Renci.SshNet.SftpClient getting failed on Azure VM
Aug 11, 2020 03:28 PM|bruce (sqlwork.com)|LINK
if you are not using a load balancer, then you just need to open the ports in two places:
1) login to the VM and and change the firewall rules to open the port
2) login to azure and open the port to the vm
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/nsg-quickstart-portal
Member
44 Points
145 Posts
Re: Renci.SshNet.SftpClient getting failed on Azure VM
Aug 11, 2020 07:09 PM|sukhdeep_kambo|LINK
Hi Bruce,
Thank you for your response. I tried it, unfortunately it did not work.
I would like to provide additional information - When I try same connection from FileZilla, it does not work there as well and throws following error:
Status: Connecting to ftp.officeally.com...
Response: fzSftp started, protocol_version=9
Command: open "XXXX@ftp.officeally.com" 22
Error: FATAL ERROR: Network error: Software caused connection abort
Error: Could not connect to server
All-Star
58144 Points
15646 Posts
Re: Renci.SshNet.SftpClient getting failed on Azure VM
Aug 11, 2020 08:21 PM|bruce (sqlwork.com)|LINK
did you create outbound rules for both the VM's firewall and the azure hosting?
Member
44 Points
145 Posts
Re: Renci.SshNet.SftpClient getting failed on Azure VM
Aug 12, 2020 03:27 AM|sukhdeep_kambo|LINK
Yes, I created on both.
All-Star
58144 Points
15646 Posts
Re: Renci.SshNet.SftpClient getting failed on Azure VM
Aug 12, 2020 03:56 AM|bruce (sqlwork.com)|LINK
then I'd check if the dns is configured correctly. use nslookup or ping to verify name lookup.
Member
44 Points
145 Posts
Re: Renci.SshNet.SftpClient getting failed on Azure VM
Aug 12, 2020 03:59 AM|sukhdeep_kambo|LINK
I have configured couple of web sites on same VM and they are working fine. So if I am not wrong, DNS is fine. I can also jump on Skype to connect and show you, if you have a moment now. I would really appreciate your help. Thank you!