sshnet / sshnet/SSH.NET

Key Exchange Negotiation Failed

Open
#1,296 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.4k
Forks
993
Avg merge
9d 21h
Merged PRs (30d)
1

Description

Hi Folks,

I am using the latest NuGet package - 2023.0.1 in a .NET 6 console app. Below is the stack trace.

Code:

               var password = _encryptionManager.Decrypt(sftpSetting.EncryptedUserPassword);
                ConnectionInfo connectionInfo;
                var methods = new List<AuthenticationMethod>
                {
                    new PasswordAuthenticationMethod(sftpSetting.Username,password)
                };
                connectionInfo = new ConnectionInfo(sftpSetting.HostName, sftpSetting.Port, sftpSetting.Username, methods.ToArray());

                using (var sftpClient = new Renci.SshNet.SftpClient(connectionInfo))
                {
                    sftpClient.HostKeyReceived += (sender, e) =>
                    {
                        e.CanTrust = GetHostFingerPrint(sftpSetting).Equals(e.FingerPrintSHA256);
                    };
                    sftpClient.Connect();
                    sftpClient.UploadFile(fileStream, remotePath);
                    sftpClient.Disconnect();
                } 

Stack Trace:

Renci.SshNet.Common.SshConnectionException
HResult=0x80131500
Message=Key exchange negotiation failed.
Source=Renci.SshNet
StackTrace:
at Renci.SshNet.Security.KeyExchange.Finish()
at Renci.SshNet.Security.KeyExchangeECDH.Finish()
at Renci.SshNet.Session.MessageListener()
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.CreateAndConnectSession()
at Renci.SshNet.BaseClient.Connect()

Is there anything I can do to workaround this issue? Thank you!

EDIT:
To add to the scenario, I have no issues connecting and uploading using a WinSCP client with the same configuration used above.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the .NET 6 connection code at SftpClient.Connect and the KeyExchangeECDH.Finish stack-trace entry. Compare the SSH negotiation configuration with the working WinSCP setup and identify the missing compatibility detail. Done means a reproducible cause and a documented workaround or confirmed fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.