import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
public class manager{
private final String chineseToFirstLetter = xx;
private final String hostName = "xx.xx.xx.xx";
private final int port = xxxx;
private final String userName = "xxxx";
private final String password = "xxxx";
//另一个服务器执行sql文件方法
scriptSql.getConn(chineseToFirstLetter);
Connection conn = new Connection(hostName,port);
Session sess = null;
try {
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(userName,
password);
if (isAuthenticated == false) {
return BaseDtoHttp.ofError(530,"连接不上服务器!");
}
sess = conn.openSession();
sess.execCommand("sh D:/test/sql.sh"+ chineseToFirstLetter);
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true) {
String line = br.readLine();
if (line == null) {
break;
}
System.out.println(line);
}
} catch (IOException e) {
return BaseDtoHttp.ofError(530,"创建失败!");
} finally {
sess.close();
conn.close();
}
}
在线等解决方案,谢谢