C#Renci.SshNet.Sftp Connect引发ArgumentNullException [英] C# Renci.SshNet.Sftp Connect throwing ArgumentNullException

查看:97
本文介绍了C#Renci.SshNet.Sftp Connect引发ArgumentNullException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Renci.SshNet.Sftp连接到SFTP.尝试调用sftpClientObject.Connect()时出现以下错误.请在错误下方找到.几天前工作正常.检查了身份验证详细信息,它是完美的.

I am using Renci.SshNet.Sftp to connect to SFTP. I am getting the following error when I try to call 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.

异常堆栈跟踪:

   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?

谢谢

推荐答案

似乎唯一可以想象的情况是,当PasswordAuthenticationMethod.Authenticate可以将未初始化的等待句柄传递给WaitHandle.WaitAny时,是在身份验证被关闭时关闭会话.进行中.

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.

如果会话因超时而关闭,则设置较高的超时可以解决问题,就像您发现自己一样.

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);


您似乎正在使用SSH.NET的旧版本(可能是NuGet中提供的2013.4.7版本).由于在更高版本中重构了代码的相关部分,因此升级也可以解决此问题.无论如何,您都应该这样做,因为NuGet SSH.NET软件包确实很旧.


You seem to be using an old version of SSH.NET (probably the version 2013.4.7 available in NuGet). 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.

这篇关于C#Renci.SshNet.Sftp Connect引发ArgumentNullException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆