private static void SSHConnect()
{
try
{
SshConnectionInfo input = GetInput();
SshShell ssh = new SshShell(input.Host, input.User);
if (input.Pass != null) ssh.Password = input.Pass;
if (input.IdentityFile != null) ssh.AddIdentityFile(input.IdentityFile);
ssh.Connect();
string pattern = "$";
ssh.ExpectPattern = pattern;
ssh.RemoveTerminalEmulationCharacters = true;
ArrayList sshscript = new ArrayList();
sshscript.Add("commands");
int i = 0;
string output = "";
while (ssh.ShellOpened)
{
if (i == 0)
output = ssh.Expect(pattern);
if (i < sshscript.Count)
{
string data = sshscript.ToString();
if (data == "") break;
ssh.WriteLine(data);
output = ssh.Expect(pattern);
i += 1;
}
else
break;
}
ssh.Close();
}
catch (Exception e)
{
string ErrMsg = e.Message;
}
}
private static SshConnectionInfo GetInput()
{
SshConnectionInfo info = new SshConnectionInfo();
info.Host = "ur host address"
info.User = "username"
info.Pass = "pwd";
return info;
}
private struct SshConnectionInfo
{
public string Host;
public string User;
public string Pass;
public string IdentityFile;
}
G.Varun
Sripriya, if this helps please login to Mark As Answer. | Alert Moderator