[J2SSH] Channel'In/Out'putStream problème
Bonjour,
Actuellement, je développe un programme permettant de se connecter en SSH à un serveur sous linux, arrivé sur ce serveur, je veux lui envoyer des commandes. Le problème c'est que je n'arrive pas utiliser la fonction write()
ChannelOutpuStream : Lien Doc ChannelOutputStream
ChannelInputStream : Lien Doc ChannelInputStream
Code:
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
|
public static void run() throws IOException
{
ConfigurationLoader.initialize(false);
String hostname = JOptionPane.showInputDialog("Quelle est le host ?");
String username = JOptionPane.showInputDialog("Quelle est le username ?");
String password = JOptionPane.showInputDialog("Quelle est le password ?");
System.out.println("Host : " + hostname + " Username : " + username + " Password : " + password);
SshClient ssh = new SshClient();
IgnoreHostKeyVerification verif = new IgnoreHostKeyVerification();
ssh.connect(hostname, verif);
PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
pwd.setUsername(username);
pwd.setPassword(password);
int result = ssh.authenticate(pwd);
if(result == AuthenticationProtocolState.COMPLETE)
{
System.out.println("sa marche");
ForwardingIOChannel channel = new ForwardingIOChannel(ForwardingIOChannel.LOCAL_FORWARDING_CHANNEL,"tarantella","***.***.***.***",22,"myhost",22);
if(ssh.openChannel(channel))
{
System.out.println("truc");
ChannelOutputStream out = channel.getOutputStream();
ChannelInputStream in = channel.getInputStream();
String commandeSSH = "ssh smtp01.msg.oleane.net";
byte[] tabCommandeSSH = commandeSSH.getBytes();
out.write(tabCommandeSSH);
System.out.println(in.read());
}
else
System.out.println("Channel pas ouvert");
}
} |
Donc je traduis une ligne de commande en tableau de bytes et je l'envoie, et ensuite je lis ce que le serveur envoie, et lui renvoie des int :s pas évident à lire :P
Qu'en pensez vous ?