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 |

SshShellTest.cs

1using System;
2using System.Collections;
3using Tamir.SharpSsh;
4using System.IO;
5
6namespace sharpSshTest.sharpssh_samples
7{
8	/// <summary>
9	/// Summary description for SshExeTest.
10	/// </summary>
11	public class SshShellTest
12	{
13		public static void RunExample()
14		{
15			try
16			{
17				SshConnectionInfo input = Util.GetInput();
18				SshShell shell = new SshShell(input.Host, input.User);
19				if(input.Pass != null) shell.Password = input.Pass;
20				if(input.IdentityFile != null) shell.AddIdentityFile( input.IdentityFile );
21
22				Console.Write("Connecting...");
23				shell.Connect();
24				Console.WriteLine("OK");
25				shell.RedirectToConsole();
26				while(shell.ShellOpened)
27				{
28					System.Threading.Thread.Sleep(500);
29				}
30				Console.Write("Disconnecting...");
31				shell.Close();
32				Console.WriteLine("OK");
33			}
34			catch(Exception e)
35			{
36				Console.WriteLine(e.Message);
37			}
38		}
39	}
40}
41

Copyright (c) 2005 TamirGal.Com