package fr.yogourt.model;
import java.io.BufferedReader;
import java.io.OutputStream;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;
public class ConnexionEDI implements UserInfo{
public JSch id;
public UserInfo ui;
public BufferedReader fromServer;
public OutputStream toServer;
private Channel channel = null;
private Session session = null;
private String passwd;
private String serv;
private String login;
public ConnexionEDI(String login, String serv, int port) throws JSchException{
this.id = new JSch();
this.login = login;
this.serv = serv;
this.session = id.getSession(this.login, this.serv, 22);
this.passwd = "edi";
}
public String getPassword(){ return passwd; }
public boolean promptYesNo(String str){ return true; }
public String getPassphrase(){ return null; }
public boolean promptPassphrase(String message){ return false; }
public boolean promptPassword(String message){ return true; }
public void showMessage(String arg0) {
System.out.println(arg0);
}
public void connectServiceEDI(){
if (!session.isConnected()){
System.out.println("session is connected : "+session.isConnected());
try {
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setPassword(passwd);
session.setUserInfo(ui);
session.connect();
channel = session.openChannel("shell");
fromServer = new java.io.BufferedReader(new
java.io.InputStreamReader((channel.getInputStream())));
toServer = channel.getOutputStream();
channel.connect(30000);
}
catch(Exception e){
System.out.println(e);
}
System.out.println("Connexion ssh au service EDI �tabli !!!");
}
else {
System.out.println("Connexion ssh au service EDI d�j� �tabli !!!");
}
}
public void disconnectServiceEDI(){
channel.disconnect();
session.disconnect();
System.out.println("D�connexion ssh au service EDI effectu�e !!!");
}
}