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");
}
} |
Partager