简体   繁体   English

C#Renci.SshNet.Sftp Connect引发ArgumentNullException

[英]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.

相关问题 验证文件是否存在,然后使用 C# 将文件从 sftp 文件夹移动到另一个文件夹(使用 Renci.SshNet.Sftp) - Verify if file existes then moving file from sftp folder to another with C# (using Renci.SshNet.Sftp) 将字符串或列表转换为 Renci.SshNet.Sftp - Convert string or list to Renci.SshNet.Sftp C# 更新密码 Renci.SshNet - C# Update cipher Renci.SshNet 随机获取 Renci.SshNet.SftpClient.Connect 抛出 SshConnectionException - Randomly getting Renci.SshNet.SftpClient.Connect throwing SshConnectionException C#Renci.SshNet:无法在SFTP根目录之外上传文件-当前工作目录中的斜杠将转换为反斜杠 - C# Renci.SshNet: Unable to upload files outside of SFTP root - slashes in current working directory are converted to backslahes C# Renci.SshNet.Common.SshAuthenticationException:“权限被拒绝(密码)。” - C# Renci.SshNet.Common.SshAuthenticationException: 'Permission denied (password).' 错误:Renci.SshNet.Common.SftpPathNotFoundException:c# 中“没有这样的文件” - error: Renci.SshNet.Common.SftpPathNotFoundException: 'No such file' in c# SFTP连接未关闭(Renci和C#) - SFTP Connections not closing (Renci & C#) 使用Renci.SshNet的SHA2服务器SFTP指纹 - SHA2 server SFTP fingerprints using Renci.SshNet 是否可以更改用户的 SFTP 密码 (renci.sshnet) - Is it possible to change a users SFTP password (renci.sshnet)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM