[英]C# Renci.SshNet.Sftp Connect throwing ArgumentNullException
I am using Renci.SshNet.Sftp to connect to SFTP. 我正在使用Renci.SshNet.Sftp连接到SFTP。 I am getting the following error when I try to call
sftpClientObject.Connect()
. 尝试调用
sftpClientObject.Connect()
时出现以下错误。 Please find below the error. 请在错误下方找到。 It was working fine couple of days ago.
几天前工作正常。 Checked the authentication details and it is perfect.
检查了身份验证详细信息,它是完美的。
var _sftpClient = new SftpClient(_hostName, _userName, _password);
using (_sftpClient)
{
_sftpClient.Connect();
// Other code to follow
}
Error:
错误:
Value cannot be null.值不能为空。
Parameter name: At least one element in the specified array was null.参数名称:指定数组中的至少一个元素为null。
Exception stacktrace: 异常stacktrace:
at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, Int32 millisecondsTimeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, TimeSpan timeout, Boolean exitContext)
at System.Threading.WaitHandle.WaitAny(WaitHandle[] waitHandles, TimeSpan timeout)
at Renci.SshNet.Session.WaitHandle(WaitHandle waitHandle)
at Renci.SshNet.PasswordAuthenticationMethod.Authenticate(Session session)
at Renci.SshNet.ConnectionInfo.Authenticate(Session session)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
at SftpPoller.FileTransferClient.ProcessFilesInSftp(TextWriter log) in
But when I use the following code, it worked: 但是当我使用以下代码时,它起作用了:
var methods = new AuthenticationMethod[1];
methods[0] = new PasswordAuthenticationMethod(_userName, _password);
var con = new ConnectionInfo(_hostName, _userName, methods) {Timeout = new TimeSpan(0, 0, 0, 60)};
_sftpClient = new SftpClient(con);
Can anyone help me how to solve this issue? 谁能帮我解决这个问题?
Thanks 谢谢
It seems that the only imaginable scenario, when the PasswordAuthenticationMethod.Authenticate
can pass an uninitialized wait handle to WaitHandle.WaitAny
is when the session is closed while the authentication is ongoing. 似乎唯一可以想象的情况是,当
PasswordAuthenticationMethod.Authenticate
可以将未初始化的等待句柄传递给WaitHandle.WaitAny
时,是在进行身份验证的同时关闭会话。
If the session is closed due to a timeout, setting a higher timeout can resolve the problem, as you have found yourself. 如果会话因超时而关闭,则设置较高的超时可以解决问题,就像您发现的那样。
A simpler code to set the timeout is: 设置超时的简单代码是:
var _sftpClient = new SftpClient(_hostName, _userName, _password);
_sftpClient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(60);
You seem to be using an old version of SSH.NET (probably the version 2013.4.7 available in NuGet). 您似乎正在使用旧版本的SSH.NET(可能是NuGet中提供的2013.4.7版本)。 As the relevant part of the code was refactored in later versions, upgrading might solve this problem too.
由于在更高版本中重构了代码的相关部分,因此升级也可以解决此问题。 You should do it anyway as the NuGet SSH.NET package is really old.
无论如何,您都应该这样做,因为NuGet SSH.NET软件包确实很旧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.