how to connect a ssh client?

Posted by Sripriya under C# on 11/21/2011 | Points: 10 | Views : 3860 | Status : [Member] | Replies : 1
Session.connect: System.NullReferenceException: Object reference not set to an instance of an object.
at Tamir.SharpSsh.jsch.jce.HMACMD5.update(Int32 i)
at Tamir.SharpSsh.jsch.Session.read(Buffer buf)
at Tamir.SharpSsh.jsch.UserAuth.start(Session session)
at Tamir.SharpSsh.jsch.UserAuthNone.start(Session session)
at Tamir.SharpSsh.jsch.Session.connect(Int32 connectTimeout)

any one help me!!!!




Responses

Posted by: Varung on: 12/5/2011 [Member] Starter | Points: 25

Up
0
Down
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

Login to post response