我在尝试使用 SFTP 客户端发送文件时遇到以下异常。它以前可以工作,但自从我迁移到 .NET 8 后,我遇到了这个异常。
Negotiation failed. Unsupported instance of ECDiffieHellman algorithm.
是否有任何特定于 SFTP 必须在 .NET 8 中完成的操作才能解决此问题?
这是供参考的代码片段。
using (var client = new Sftp())
{
try
{
var privateKey = KeyFromString(Configuration.KeyString);
var stream = StreamFromString(contents);
client.Connect(Configuration.Url, Configuration.Port);
client.Login(Configuration.User, Configuration.Password, privateKey);
client.PutFile(stream, filename);
return true;
}
catch (Exception ex)
{
throw ex;
}
finally
{
try
{
if (client != null) { client.Disconnect(); }
}
catch { }
}
}
我尝试检查在 .NET 8 中使用 SFTP 的任何指南,但找不到任何相关内容。
这是堆栈跟踪(如果有帮助),已更新以隐藏敏感信息:
Inner exception Rebex.Net.SftpException handled at PutFile:
at Rebex.Net.Sftp.viema (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at Rebex.Net.Sftp.mksfi (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at Rebex.Net.Sftp.Connect (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at PutFile
Inner exception Rebex.Net.SshException handled at Rebex.Net.Sftp.viema:
at Rebex.Net.SshSession.lawoz (Rebex.Networking undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at Rebex.Net.SshSession.Negotiate (Rebex.Networking undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at Rebex.Net.Sftp+ymnzg.zbkwa.igvda (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at Rebex.Net.Sftp.viema (Rebex.Sftp undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
Inner exception System.Security.Cryptography.CryptographicException handled at Rebex.Net.SshSession.lawoz:
at ymnzg.aoqsw.kaxgn (Rebex.Common undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at ymnzg.aoqsw.kiovp (Rebex.Common undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at ymnzg.lmfzi.bltdt (Rebex.Common undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at Rebex.Security.Cryptography.AsymmetricKeyAlgorithm.scqfy (Rebex.Common undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at ymnzg.yajog.dlafz (Rebex.Networking undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
at Rebex.Net.SshSession.lawoz (Rebex.Networking undefined, Version=5.0.7733.0 undefined, Culture=neutral undefined, PublicKeyToken=1c4638788972655d undefined)
这是由旧版本的 Rebex SFTP 和 .NET 7/8 的
ECDiffieHellman
类之间的兼容性问题引起的。此问题已在 Rebex SFTP v6.0.8181 中得到修复。该版本可能适用于 .NET 8,但不受官方支持。
第一个正式支持 .NET 8 的 Rebex SFTP 版本是 Rebex SFTP v7.0.8720。以前的版本尚未使用 .NET 8 进行测试,因为它尚不可用。
您使用的是 Rebex SFTP v5.0.7733,该版本于 2021 年初发布。它支持 .NET 5,但尚未使用 .NET 6、7 或 8 进行测试,并且不受任何这些平台支持。