我写了一个类 ,用来登陆设备,发送设备命令 "get config".来获取 设备的配置.
public class CopyOfSSH2Getpolicy {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String tftpName ="juniper_"+ format.format(date);
System.out.println("start time ----------"+tftpName);
CopyOfSSH2Getpolicy ssh = new CopyOfSSH2Getpolicy(tftpName,"ssh");
ssh.setValues("192.168.2.230", "netscreen", "netscreen");
ssh.startGUI();

}
static final String knownHostPath = "~/.ssh/known_hosts";
static final String idDSAPath = "~/.ssh/id_dsa";
static final String idRSAPath = "~/.ssh/id_rsa";
KnownHosts database = new KnownHosts();
String hostname;
String username;
String password;
public String result;
String tftpName;
String devAcion;
         //这里是初始化一些参数
public CopyOfSSH2Getpolicy(String tftpName,String devAcion) {
this.tftpName = tftpName;
this.devAcion = devAcion;
File knownHostFile = new File(knownHostPath);
if (knownHostFile.exists()) {
try {
database.addHostkeys(knownHostFile);
} catch (IOException e) {
}
}
} class TerminalDialog {
private static final long serialVersionUID = 1L; Session sess;
InputStream in;
OutputStream out;
FileReader filereader = null; public TerminalDialog(Session sess) throws IOException {
this.sess = sess;

in = sess.getStdout();
out = sess.getStdin();
String str = "set console page 0" + "\n" + "get config" + "\n"+ "set console page 24" + "\n";

if (str != null) {
byte[] c = new byte[str.length()];
c = str.getBytes();
out.write(c);
out.write(10);
byte[] buff = new byte[8192];
String file = "";
while (true) {
int len = in.read(buff);
if (len == -1)
return;
for (int i = 0; i < len; i++) {
char o = (char) (buff[i] & 0xff);
file = file + String.valueOf(o).toString();
}

if (file.indexOf("set console page 24") != -1) {
                                                // 将最后的结果写入文件
write(FileUri.configpath, file);
result = "ssh成功!";
in.close();
out.close();
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String tftpName ="juniper_"+ format.format(date);
System.out.println("end time ----------"+tftpName);
}
}
}
} public void write(String path, String content) {
String s1 = new String();
try {
File f = new File(path);
if (f.exists()) {
System.out.println("文件存在");
f.delete();
System.out.println("文件被删除...");
f.createNewFile();
System.out.println("文件创建成功!");
}
s1 += content; BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} class ConnectionThread extends Thread {
String hostname;
String username; public ConnectionThread(String hostname, String username) {
this.hostname = hostname;
this.username = username;
} public void run() {
Connection conn = new Connection(hostname); try {
conn.connect();
while (true) {

if (conn.isAuthMethodAvailable(username, "password")) { boolean res = conn.authenticateWithPassword(username,
password); if (res == true)
break;
continue;
} } Session sess = conn.openSession(); sess.startShell();
TerminalDialog td = new TerminalDialog(sess);
sess.close();
} catch (IOException e) {
e.printStackTrace();
}

conn.close();
}
} void loginPressed() { ConnectionThread ct = new ConnectionThread(hostname, username);
ct.start();
} public void startGUI() {
Runnable r = new Runnable() {
public void run() {
loginPressed();
}
};
SwingUtilities.invokeLater(r);
}
         //这里是初始化设备 ip username 和 password 参数
public void setValues(String host, String uname, String pwd) {
this.setHostname(host);
this.setPassword(pwd);
this.setUsername(uname);
} public String getHostname() {
return hostname;
} public void setHostname(String hostname) {
this.hostname = hostname;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getResult() {
return result;
} public void setResult(String result) {
this.result = result;
} public String getTftpName() {
return tftpName;
} public void setTftpName(String tftpName) {
this.tftpName = tftpName;
} public String getDevAcion() {
return devAcion;
} public void setDevAcion(String devAcion) {
this.devAcion = devAcion;
}}
 问题是  当我使用这个类 获取设备的配置(config)的时候.如果config特别的大(例如: 有2MB)
         这样通过流远程过来.就超级慢了. 要40分钟.还有可能session超时哦.
         注:tftp方式的已经实现.由于有些设备不支持tftp.请高手帮忙呀...