public static void main(String[] args) throws Exception { SFTPTest test = new SFTPTest(); Map<String, String> sftpDetails = sftpDetails_194; SFTPChannel channel = test.getSFTPChannel(); ChannelSftp chSftp = channel.getChannel(sftpDetails, 60000); System.out.println(">>> >>> begin ...... "); Boolean restart = false; String src = ""; String dst = ""; /** ************************ chetuan ************************* */ // ftl if (ftl_boo) { src = "D:\\workspace_java\\" + app + "\\WebContent\\"; // 本地文件名 dst = tom_path + tomcat + "/webapps/" + app + "/"; // 目标文件名 putDirectory(src, dst, chSftp, contain_ftl); } // class if (class_boo) { src = "D:\\workspace_java\\" + app + "\\build\\classes\\"; dst = tom_path + tomcat + "/webapps/" + app + "/WEB-INF/classes/"; putDirectory(src, dst, chSftp, contain_class); restart = true; } // html if (html_boo) { src = "D:\\workspace_java\\" + app + "\\WebContent\\db12\\css"; // 本地文件名 dst = "/data/app/apache2/hd_html/"; // 目标文件名 putDirectory(src, dst, chSftp, contain_html); } // 重启tomcat if (restart) { ChannelShell channelShell = channel.getChannelShell(); if (channelShell != null) { // 获取输入流和输出流 InputStream instream = channelShell.getInputStream(); OutputStream outstream = channelShell.getOutputStream(); // 发送需要执行的SHELL命令,需要用\n结尾,表示回车 String shellCommand = tom_path + tomcat + "/bin/stop.sh \n"; outstream.write(shellCommand.getBytes()); outstream.flush(); // System.out.println("comm_1 >>> "+getCommRes(instream)); // 缓冲时间 System.out.println(">>> tomcat is bean stop"); Thread.sleep(5 * 1000); // start shellCommand = tom_path + tomcat + "/bin/up.sh \n"; outstream.write(shellCommand.getBytes()); outstream.flush(); System.out.println(">>> tomcat is bean start"); Thread.sleep(5 * 1000); shellCommand = "ps -ef|grep " + tomcat + " |grep -v grep \n"; outstream.write(shellCommand.getBytes()); outstream.flush(); Thread.sleep(5 * 1000); System.out.println("linux: >>> \n" + getCommRes(instream)); outstream.close(); instream.close(); channelShell.disconnect(); } } chSftp.quit(); channel.closeChannel(); System.out.println(">>> >>> done ...... "); }