【发布时间】:2016-01-22 18:20:39
【问题描述】:
我第一次使用库 Renci.SshNet.dll。我下载的是2014.4.6-beta2版本。
我想通过 ssh 连接到服务器。当然,使用我的登录名和密码可以使用 Putty 进行连接。
这是我的代码:
Dim PWAuthMeth = New PasswordAuthenticationMethod(Login, Password)
Dim KIAuthMeth = New KeyboardInteractiveAuthenticationMethod(Login)
Dim ConnectionInfo As New ConnectionInfo(ServerName, 22, Login, PWAuthMeth, KIAuthMeth)
Dim SshClient1 As New SshClient(ConnectionInfo)
SshClient1.Connect()
connect() 方法给了我一个 ArgumentNullException,消息(法语):
"La valeur ne peut pas être null. Nom du paramètre : data"
堆栈跟踪:
à Renci.SshNet.KeyboardInteractiveAuthenticationMethod.Authenticate(Session session)
à Renci.SshNet.AuthenticationMethod.Renci.SshNet.IAuthenticationMethod.Authenticate(ISession session)
à Renci.SshNet.ClientAuthentication.TryAuthenticate(ISession session, AuthenticationState authenticationState, ICollection`1 allowedAuthenticationMethods, SshAuthenticationException& authenticationException)
à Renci.SshNet.ClientAuthentication.Authenticate(IConnectionInfoInternal connectionInfo, ISession session)
à Renci.SshNet.ConnectionInfo.Authenticate(ISession session)
à Renci.SshNet.Session.Connect()
à Renci.SshNet.BaseClient.Connect()
à ConsoleApplication1.Upload.LancerUpload() dans D:\Travail\ENSAM\Promotion\Logiciel\PromoAM-Export\PromoAM-Export\Class_Upload.vb:ligne 19
...
我尝试了其他版本的dll,但错误是一样的。
我找到了这个话题:
Unable to connect to AIX(Unix) box with SSH.NET Library - Error : Value cannot be null
问题似乎很相似,所以我尝试将c#翻译成vb.net:
Private Sub HandleKeyEvent(sender As Object, e As Renci.SshNet.Common.AuthenticationPromptEventArgs)
For Each prompt As Renci.SshNet.Common.AuthenticationPrompt In e.Prompts
If prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) <> -1 Then
prompt.Response = Password
End If
Next
End Sub
但是
KIAuthMeth.AuthenticationPrompt += ...
无法识别。我被卡住了。
有什么想法吗?我走对了吗?
【问题讨论】:
-
“无法识别”是什么意思? SSH.NET 2014.4.6-beta2 中有
KeyboardInteractiveAuthenticationMethod.AuthenticationPrompt。 -
好吧,你不知道如何在 VB.NET 中分配事件处理程序,对吧?
-
我不知道如何分配活动,但现在我知道了;)谢谢
-
实际上,我无法选择 AuthenticationPrompt 事件,因为我以“KIAuthMeth”开头。所以,我不知道如何分配事件,但现在我知道了;)谢谢。我认为这篇文章不是重复的,因为最初的问题涉及 KeyboardInteractiveAuthenticationMethod。但是,它可能与我引用的帖子重复,只是语言不同。
-
我相信您的实际问题已在stackoverflow.com/q/15686276/850848 中解决,但您缺少的是如何将其转换为 VB.NET。这就是你应该发布的问题,我已将其标记为重复。
标签: vb.net ssh c#-to-vb.net