用网上找到的SSH.NET连接远程FTP主机,大致代码如下:
using Renci.SshNet;
using Renci.SshNet.Common;
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
string user_Name = config.AppSettings.Settings["SSHUserName"].Value;
string passWord = config.AppSettings.Settings["SSHpassword"].Value;
string server_Ip = config.AppSettings.Settings["ftpServer"].Value;
PasswordConnectionInfo sshConnectionInfo = new PasswordConnectionInfo(server_Ip, user_Name, passWord);
SshClient cSSH = new SshClient(sshConnectionInfo);
cSSH.Connect();
SshCommand exec = cSSH.RunCommand("locate " + this.cbBoxName.Text);
string All_result = exec.Result; // shell 返回结果是一个String
然后就在
cSSH.Connect();
这里报错,保存信息如下:
Value cannot be null or empty,All lists either null or empty
at Renci.SshNet.KeyboardInteractiveAuthenticationMethod.Authenticate(Session session)
at Renci.SshNet.ConnectionInfo.Authenticate(Session session)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
解决方法,换上SSH.NET最新版本的dll,最新版本为2016.1.0-beta2,更新于2017年8月17日,下载链接:SSH.NET最新dll集合(2017年8月)。