Rebex.Sftp Intermittent connection problem

0 votes
asked Jul 18 by PeterTabangan (150 points)

We are getting intermittent connection problem using Rebex SFTP
below are the exception that we capture on our log

{
"Depth": 0,
"ClassName": "Rebex.Net.SftpException",
"Message": "No connection could be made because the target machine actively refused it.",
"Source": "Rebex.Sftp",
"StackTraceString": " at Rebex.Net.Sftp.XM(String A, Int32 B, SshParameters C, BNB D)\r\n at Rebex.Net.Sftp.WM(String A, Int32 B, SshParameters C)\r\n at Stream.Business.Managers.SftpFileDownloaderManager.CopyOrMoveFile(SftpFileToDownload sftpFileToDownload, DownloadFileFolder downloadFileFolder, FileOperationDelegate fileOperation, String& destinationFileName)\r\n at Stream.Business.Managers.SftpFileDownloaderManager.CopyFile(SftpFileToDownload sftpFileToDownload, DownloadFileFolder downloadFileFolder, String& destinationFileName)\r\n at Stream.AmosImport.Bus.Consumers.DocumentNotificationProcessor.<>cDisplayClass13_0.b0()\r\n at Stream.AmosImport.Bus.Consumers.DocumentNotificationProcessor.d__17.MoveNext()",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": {
"Name": "XM",
"AssemblyName": "Rebex.Sftp",
"AssemblyVersion": "3.0.5715.0",
"AssemblyCulture": "",
"ClassName": "Rebex.Net.Sftp",
"Signature": "Void XM(System.String, Int32, Rebex.Net.SshParameters, Rebex.Net.BNB)",
"MemberType": 8
},
"HResult": -2146233088,
"HelpURL": null
},
{
"Depth": 1,
"ClassName": "Rebex.Net.ProxySocketException",
"Message": "No connection could be made because the target machine actively refused it.",
"Source": "Rebex.Networking",
"StackTraceString": " at Rebex.Net.OEB.XC(IAsyncResult A, String B)\r\n at Rebex.Net.OEB.SB(IAsyncResult A)\r\n at Rebex.Net.ProxySocket.Connect(String serverName, Int32 serverPort)\r\n at Rebex.Net.Sftp.XM(String A, Int32 B, SshParameters C, BNB D)",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": {
"Name": "XC",
"AssemblyName": "Rebex.Networking",
"AssemblyVersion": "3.0.5715.0",
"AssemblyCulture": "",
"ClassName": "Rebex.Net.OEB",
"Signature": "System.Object XC(System.IAsyncResult, System.String)",
"MemberType": 8
},
"HResult": -2146233088,
"HelpURL": null
},
{
"Depth": 2,
"ClassName": "Rebex.Net.ProxySocketException",
"Message": "No connection could be made because the target machine actively refused it.",
"Source": "Rebex.Networking",
"StackTraceString": " at Rebex.Net.OEB.YC(String A, IPAddress B, Int32 C)",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": {
"Name": "YC",
"AssemblyName": "Rebex.Networking",
"AssemblyVersion": "3.0.5715.0",
"AssemblyCulture": "",
"ClassName": "Rebex.Net.OEB",
"Signature": "Void YC(System.String, System.Net.IPAddress, Int32)",
"MemberType": 8
},
"HResult": -2146233088,
"HelpURL": null
},
{
"Depth": 3,
"ClassName": "System.Net.Sockets.SocketException",
"Message": "No connection could be made because the target machine actively refused it 172.26.0.64:22",
"Source": "System",
"StackTraceString": " at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)\r\n at Rebex.Net.OEB.YC(String A, IPAddress B, Int32 C)",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": {
"Name": "DoConnect",
"AssemblyName": "System",
"AssemblyVersion": "4.0.0.0",
"AssemblyCulture": "",
"ClassName": "System.Net.Sockets.Socket",
"Signature": "Void DoConnect(System.Net.EndPoint, System.Net.SocketAddress)",
"MemberType": 8
},
"HResult": -2147467259,
"HelpURL": null
}

kind regards
Peter Tabangan

Applies to: Rebex SFTP

1 Answer

0 votes
answered Jul 18 by Lukas Matyska (39,480 points)
selected Jul 19 by PeterTabangan
 
Best answer

The exception "No connection could be made because the target machine actively refused it 172.26.0.64:22" usually means that the remote SFTP server is not running (no one listen at 172.26.0.64 port 22).

Please ensure that the SFTP server is running and you are able to connect to it using any SSH client.

Alternatively, it can be caused by server's DDoS protection. If too much connections are requested to the server, the server refuses some of them. Please ensure this is not the case.

commented Jul 18 by PeterTabangan (150 points)
Hi Lukas,
   Thank yo for your reply, I think second scenario is most likely the case (DDoS). Since we have service that is constantly connecting to SFTP server to download file every time it receive message and we always initiate new Instance of Rebex.Sftp object since the connection property is base on the customer information which is define on the message . Is there a away the to cache the Rebex.Sftp connection session so that we can reuse it if same customer information received ? Or any best practice to handle this kind of scenario ?

thank you in advance
Peter Tabangan
commented Jul 18 by Lukas Matyska (39,480 points)
There is no built-in cache, however you can simply keep reference to the Sftp object and use it later for the same user.

You can also keep alive such inactive connections by calling KeepAlive() method (e.g. every 60 seconds). If the particular instance is not used (e.g. for more than 1 hour) you can discard it.
commented Jul 20 by PeterTabangan (150 points)
Is there a way to check if the SFTP session has an active activity (e.g. downloading , uploading) before disposing or closing connection.
commented Jul 20 by Lukas Matyska (39,480 points)
No, there is no such method. Sorry.

It is not well defined, what should it mean. What about opened file handles? What about directory listings?

It can be simply implemented like this:

    int activeTransfers = 0;

    try
    {
        Interlocked.Increment(ref activeTransfers);
        // do an operation ...
    }
    finally
    {
        Interlocked.Decrement(ref activeTransfers);
    }
...