1
/* -*-mode:java; c-basic-offset:2; -*- */
2
import com.jcraft.jsch.*;
4
import java.awt.event.*;
10
public static void main(String[] arg){
15
//jsch.setKnownHosts("/home/foo/.ssh/known_hosts");
17
String host=JOptionPane.showInputDialog("Enter username@hostname",
18
System.getProperty("user.name")+
20
String user=host.substring(0, host.indexOf('@'));
21
host=host.substring(host.indexOf('@')+1);
23
Session session=jsch.getSession(user, host, 22);
24
//session.setPassword("your password");
26
// username and password will be given via UserInfo interface.
27
UserInfo ui=new MyUserInfo();
28
session.setUserInfo(ui);
30
//java.util.Hashtable config=new java.util.Hashtable();
31
//config.put("StrictHostKeyChecking", "no");
32
//session.setConfig(config);
36
Channel channel=session.openChannel("shell");
38
channel.setInputStream(System.in);
39
channel.setOutputStream(System.out);
44
System.out.println(e);
48
public static class MyUserInfo implements UserInfo{
49
public String getPassword(){ return passwd; }
50
public boolean promptYesNo(String str){
51
Object[] options={ "yes", "no" };
52
int foo=JOptionPane.showOptionDialog(null,
55
JOptionPane.DEFAULT_OPTION,
56
JOptionPane.WARNING_MESSAGE,
57
null, options, options[0]);
62
JTextField passwordField=(JTextField)new JPasswordField(20);
64
public String getPassphrase(){ return null; }
65
public boolean promptPassphrase(String message){ return true; }
66
public boolean promptPassword(String message){
67
Object[] ob={passwordField};
69
JOptionPane.showConfirmDialog(null, ob, message,
70
JOptionPane.OK_CANCEL_OPTION);
71
if(result==JOptionPane.OK_OPTION){
72
passwd=passwordField.getText();
77
public void showMessage(String message){
78
JOptionPane.showMessageDialog(null, message);