| The following uses an SSH component to
create an SSH session:
[Code][EXE]
which the code is:
using System;
using Tamir.SharpSsh;
using System.Threading;
using System.IO;
// based on http://www.tamirgal.com/home/dev.aspx?Item=sharpSsh#download
namespace sharpSshTest
{
public class sharpSshTest
{
public static void Main()
{
RunExample();
}
public static void RunExample()
{
try
{
SshConnectionInfo input = GetInput();
SshShell shell = new SshShell(input.Host, input.User);
if(input.Pass != null) shell.Password = input.Pass;
shell.RedirectToConsole();
Console.Write("Connecting...");
shell.Connect();
Console.WriteLine("Details: \r\nMAC-"+shell.Mac+
"\r\nPort: "+shell.Port+
"\r\nCipher: "+shell.Cipher);
while(shell.ShellOpened)
{
System.Threading.Thread.Sleep(500);
}
Console.Write("Disconnecting...");
shell.Close();
Console.WriteLine("OK");
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
public static SshConnectionInfo GetInput()
{
SshConnectionInfo info = new SshConnectionInfo();
Console.Write("Enter Remote Host: ");
info.Host = Console.ReadLine();
Console.Write("Enter Username: ");
info.User = Console.ReadLine();
Console.Write("Enter Password: ");
info.Pass = Console.ReadLine();
Console.WriteLine();
return info;
}
public struct SshConnectionInfo
{
public string Host;
public string User;
public string Pass;
}
}
}
Which gives the following:
Enter Remote Host: ftp1.dcs.napier.ac.uk
Enter Username: cs**
Enter Password: ******
Connecting...Details:
MAC-hmac-md5
Port: 22
Cipher: 3des-cbc
Last login: Tue Jan 23 21:15:43 2007 from user-514da235.l2.c1.dsl.pol.co.uk
Directory: /home/cs72
Tue Jan 23 21:19:30 GMT 2007
socweb1:~> ls
where the MAC method is defined as hmac-md5, and the cipher scheme
is 3DES. Also the port is 22.
|