tamirgal.com logo


SharpSSH examples

The following samples are raw examples of how to directly use the JSch API from sharpSSH. The samples were translated from the java examples found on JSch homepage.

Please select a sample:


AES.cs | ChangePassphrase.cs | KeyGen.cs | KnownHosts.cs | PortForwardingL.cs | PortForwardingR.cs | ScpFrom.cs | Scp.cs | ScpTo.cs | Sftp.cs | Shell.cs | SshExeTest.cs | SshExpectTest.cs | SshFileTransferTest.cs | SshShellTest.cs | StreamForwarding.cs | Subsystem.cs | UserAuthPubKey.cs | Util.cs | README.txt |

SshExeTest.cs

1using System;
2using System.Collections;
3using Tamir.SharpSsh;
4
5namespace sharpSshTest.sharpssh_samples
6{
7	/// <summary>
8	/// Summary description for SshExeTest.
9	/// </summary>
10	public class SshExeTest
11	{
12		public static void RunExample()
13		{
14			try
15			{
16				SshConnectionInfo input = Util.GetInput();
17				SshExec exec = new SshExec(input.Host, input.User);
18				if(input.Pass != null) exec.Password = input.Pass;
19				if(input.IdentityFile != null) exec.AddIdentityFile( input.IdentityFile );
20
21				Console.Write("Connecting...");
22				exec.Connect();
23				Console.WriteLine("OK");
24				while(true)
25				{
26					Console.Write("Enter a command to execute ['Enter' to cancel]: ");
27					string command = Console.ReadLine();
28					if(command=="")break;
29					string output = exec.RunCommand(command);				
30					Console.WriteLine(output);
31				}
32				Console.Write("Disconnecting...");
33				exec.Close();
34				Console.WriteLine("OK");
35			}
36			catch(Exception e)
37			{
38				Console.WriteLine(e.Message);
39			}
40		}
41	}
42}
43

Copyright (c) 2005 TamirGal.Com