Bonjour,

J'utilise SharpSSH pour me connecter en SSH en C#
J'ai trouvé un programme tout fait ici:
http://www.codeproject.com/KB/IP/sha...px?msg=2151357

j'ai téléchargé les sources que je veux modifier pour pouvoir envoyer des commandes prédéfinies dans le code en SSH (ex: ifconfig)

Dans le code, il redirige le flux vers la console...
J'aimerais créer un flux et envoyer ma commande dedans et puis récupérer le résultat...

voici une partie du code source un peu modifié:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
public static void RunExample(String[] arg)
{
	try
	{
		//Create a new JSch instance
		JSch jsch=new JSch();
 
		//Prompt for username and server host
		//Console.WriteLine("Please enter the user and host info at the popup window...");
		String host = "ip";
 
                /*"InputForm.GetUserInput                                             *
			("Enter username@hostname",
		Environment.UserName+"@localhost");*/
		String user= "root";
 
                //host.Substring(0, host.IndexOf('@'));
                //host = ;//host.Substring(host.IndexOf('@')+1);
 
		//Create a new SSH session
		Session session=jsch.getSession(user, host, 4118);
 
		// username and password will be given via UserInfo interface.
		UserInfo ui=new MyUserInfo();
		session.setUserInfo(ui);
 
		//Connect to remote SSH server
		session.connect();			
 
		//Open a new Shell channel on the SSH session
		Channel channel=session.openChannel("shell");
 
		//Redirect standard I/O to the SSH channel
                //channel.getInputStream();
 
              /*  byte[] buffer = StrToByteArray("ifconfig");
               channel.getInputStream().Write(buffer, 0, 0);
                channel.getOutputStream().Read(buffer, 0, 0);*/
 
                channel.setInputStream(Console.OpenStandardInput());
               channel.setOutputStream(Console.OpenStandardOutput());
 
		//Connect the channel
		channel.connect();
 
                //streamWrite.Write("show sysinfo");
 
                Console.WriteLine("-- Shell channel is connected using the {0} cipher", 
		session.getCipher());
 
		//Wait till channel is closed
		while(!channel.isClosed())
		{
			System.Threading.Thread.Sleep(500);
		}
 
		//Disconnect from remote server
		channel.disconnect();
 
                session.disconnect();			
 
	}
	catch(Exception e)
	{
		Console.WriteLine(e);
	}
}
J'ai pensé que faire un :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 byte[] buffer = StrToByteArray("ifconfig");
 channel.getInputStream().Write
pour écrire la commande dans mon flux était une idée...


Est-ce que quelqu'un a des idées?


Merci d'avance