0 votes
by (600 points)

I am getting below exception while connecting to SFTP server via Rebex. SFTP "Authentication process Failed with Exception: No connection could be made because the target machine actively refused it"

I am suing Rebex dll with version 6.0.8372.0 and my application is working in .net framework 4.6.1. with WINSCP connectivity is fine. Also telnet was tried for the IP with port and it is also fine.

Connectivity Code in c#
Sftp objSFTP
objSFTP.Connect(sSFTPHost[0], int.Parse(sSFTPHost[1]));
objSFTP.Login(sSFTPHost[2], sSFTPHost[3]);
.

1 Answer

0 votes
by (147k points)

Try connecting using .NET API. Does this work, or does it fail with "No connection coud be made ..." as well?

using System.Net;
using System.Net.Sockets;
using System.Linq;

var entry = Dns.GetHostEntry(sSFTPHost[0]);
var address = entry.AddressList.Where(address => address.AddressFamily == AddressFamily.InterNetwork).First();
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(address, int.Parse(sSFTPHost[1]));
by (600 points)
using System.Net;
using System.Net.Sockets;
using System.Linq;

var entry = Dns.GetHostEntry(sSFTPHost[0]);
var address = entry.AddressList.Where(address => address.AddressFamily == AddressFamily.InterNetwork).First();
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(address, int.Parse(sSFTPHost[1]));

In the above code we are simply connecting using SFTP host and port. There is no rebex library referred here. So how can we confirm issue is not with rebex package. Also the connectivity timed out or target machine refused exception is happening in between only
by (147k points)
Yes, there is no Rebex library referenced here. Therefore, if the code still fails with the same error, it would strongly suggest that the issue is not in Rebex library, but elsewhere. Of course, if that degree of certainty is not sufficient for you, a network protocol analyzer such as Wireshark is the way to go.
by (600 points)
This exception is happening intermittently. I am using a windows service to connect to SFTP and upload/download files. Hence how can I ensure it is not rebex library related issue . If I use an exe and check same code on the button click at that time connection may.be fine but in between connectivity issue may be there
by (147k points)
You can ensure that this is not a Rebex library related issue by giving the code actually a try.

You will then find out that either (a) it works fine all the time, (b) an exception is happening intermittently, or (c) an exception is happening all the time. I assume that you will discover that (b) is what's going on, which would mean same behavior as Rebex, ensuring this is not a Rebex issue.

However, if you instead find out that (a) is the case, then it would indicate there indeed might be an issue in Rebex library that no one else suffers from, and we would then help you resolve it. (The third behavior (c) is very unlikely.)
...