Hi Arne Thx for your reply but this didnot solve my problem:
What I actually try to do is:
1). Try to setup a connection ==TcpClient client = new
TcpClient("10.31.46.20", 5022); (5022 is the port. This is the ssh port
nummer on the system)
2). Now I must send or receive some authentication (in may case
authentication is not needed) but what If I do need authentication? At this
point I don't now how to accomplish this
3). When authentication was successful, then the system (where i try to
connect to) will send me a login prompt,
4). Then my program will send the loginname and will wait for the password
prompt.
3). My program will send the password and will wait for the terminal
settings etc
So what I want my program to do after a succesful connect is, wait for some
specific character like (login: ) and send some string to the system.
I have put my test program here but I am stuck right now. I don't know how
to send or wait for athentication and also don't know how to send commands to
the system
I hope you or someone can help me wth this.
The code below I found at:
http://msdn2.microsoft.com/en-us/lib...sslstream.aspx
==========================================
using System;
using System.Collections;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.IO;
namespace Examples.System.Net
{
public class SslTcpClient
{
public static void RunClient()
{
TcpClient client = new TcpClient("10.31.46.20", 5022);
Console.WriteLine("Client connected");
SslStream sslStream = new SslStream(client.GetStream());
<< AT THIS POINT AUTHENTICATION MUST TAKE PLACE >>>
string serverMessage = ReadMessage(sslStream);
byte[] message = Encoding.UTF8.GetBytes("Hello from
client.<EOF>");
sslStream.Write(message);
sslStream.Flush();
//read message from server
//string serverMessage = ReadMessage(sslStream);
Console.WriteLine("server says: {0}", serverMessage);
//close connection
client.Close();
}
static string ReadMessage(SslStream sslStream)
{
// Read the message sent by the server.
// The end of the message is signaled using the
// "<EOF>" marker.
byte[] buffer = new byte[2048];
StringBuilder messageData = new StringBuilder();
int bytes = -1;
do
{
bytes = sslStream.Read(buffer, 0, buffer.Length);
// Use Decoder class to convert from bytes to UTF8
// in case a character spans two buffers.
Decoder decoder = Encoding.UTF8.GetDecoder();
char[] chars = new char[decoder.GetCharCount(buffer, 0,
bytes)];
decoder.GetChars(buffer, 0, bytes, chars, 0);
messageData.Append(chars);
// Check for EOF.
if (messageData.ToString().IndexOf("<EOF>") != -1)
{
break;
}
} while (bytes != 0);
return messageData.ToString();
}
public static int Main(string[] args)
{
SslTcpClient.RunClient();
return 0;
}
}
}
"Arne Vajhøj" wrote:
Sharief wrote:
I must write a client program in C# which will communicate with a switch
throught telnet.
When I create a socket connection on port 22, the switch responds with some
text and at the end with some unreadable characters. I found out that the
operating system of the switch is redhat and the protocol =
SSH-2.0-openssh_3.9p1.
My problem:
1. I connect with socket <ip-address>:<port 22>
2. I don't get the prompt:"login: " but my programs says connected
3. after a while a timeout occurs with the comment: "Timed Out waiting for :
login"
My question is:
- Where can I download a ssl classfile for c# which support openssl
- How can I catch a certificate if a server sends one and how can I write my
one
- do you have an example how to write this (I' am new to C# + ssl)
Try one of:
http://www.tamirgal.com/home/dev.aspx?Item=SharpSsh
http://www.routrek.co.jp/en/product/.../granados.html
Arne