我正在使用Renci.SshNet.Sftp连接到SFTP。当我尝试拨打sftpClientObject.Connect()
时出现以下错误。请在下面找到错误。几天前它工作正常。检查了验证细节,它是完美的。C#Renci.SshNet.Sftp连接抛出ArgumentNullException
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
但是,当我使用下面的代码,它的工作:
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);
谁能帮助我如何解决这个问题?
感谢
你能告诉我们异常stacktrace吗? –
你确定没有'_hostName','_userName','_password'为空吗? –
_hostName,_userName,_password不为空。 –