public bool RunSSHCode(string Code, ref string resultmessage) { Chilkat.Ssh ssh = new Chilkat.Ssh(); bool success = ssh.Connect(DestinationAdress, Port); if (success != true) { Debug.WriteLine(ssh.LastErrorText); return(false); } // Wait a max of 5 seconds when reading responses.. ssh.IdleTimeoutMs = 5000; // Authenticate using login/password: success = ssh.AuthenticatePw(UserName, _password); if (success != true) { Debug.WriteLine(ssh.LastErrorText); return(false); } // Send some commands and get the output. resultmessage = ssh.QuickCommand(Code, "ansi"); if (ssh.LastMethodSuccess != true) { Debug.WriteLine(ssh.LastErrorText); return(false); } Debug.WriteLine(resultmessage); return(true); }
public static void newMethod() { // This example assumes Chilkat SSH/SFTP to have been previously unlocked. // See Unlock SSH for sample code. Chilkat.Ssh ssh = new Chilkat.Ssh(); // Any string automatically begins a fully-functional 30-day trial. bool suc = ssh.UnlockComponent("Anything for 30-day trial"); if (suc != true) { Console.WriteLine(ssh.LastErrorText); return; } int port = 22; bool success = ssh.Connect("172.24.16.155", port); if (success != true) { Console.WriteLine(ssh.LastErrorText); return; } // Authenticate using login/password: success = ssh.AuthenticatePw("harinath", "1234"); if (success != true) { Console.WriteLine(ssh.LastErrorText); return; } // Send some commands and get the output. string strOutput = ssh.QuickCommand("df", "ansi"); if (ssh.LastMethodSuccess != true) { Console.WriteLine(ssh.LastErrorText); return; } Console.WriteLine("---- df ----"); Console.WriteLine(strOutput); strOutput = ssh.QuickCommand("echo hello world", "ansi"); if (ssh.LastMethodSuccess != true) { Console.WriteLine(ssh.LastErrorText); return; } Console.WriteLine("---- echo hello world ----"); Console.WriteLine(strOutput); strOutput = ssh.QuickCommand("date", "ansi"); if (ssh.LastMethodSuccess != true) { Console.WriteLine(ssh.LastErrorText); return; } Console.WriteLine("---- date ----"); Console.WriteLine(strOutput); }