[JSch-users] simple mkdir exec command using jsch
Status: Alpha
Brought to you by:
ymnk
|
From: Marot L. <lau...@al...> - 2008-05-23 21:23:04
|
Hello, I've got the following jsp that works fine .... but only once ! If y re-submit the page, code is no more executed (can't see "file already exists" in the logs). Could it be some kind of session persistence ? Thanks <%@ page import="com.jcraft.jsch.*,java.io.*,java.util.*" %> <% try{ JSch jsch=new JSch(); String host="tomcat@10.1.1.133"; String user=host.substring(0, host.indexOf('@')); host=host.substring(host.indexOf('@')+1); Session sessionJSH=jsch.getSession(user, host, 22); sessionJSH.setPassword("alliacom"); java.util.Hashtable configJSH=new java.util.Hashtable(); configJSH.put("StrictHostKeyChecking", "no"); sessionJSH.setConfig(configJSH); sessionJSH.connect(); Date date = new Date(); System.out.println("commande ok "+date); out.println("commande ok "+date); String command="mkdir /usr/local/jakarta-tomcat-4.1.29/webapps/test"; Channel channel=sessionJSH.openChannel("exec"); ((ChannelExec)channel).setCommand(command+"\n"); ((ChannelExec)channel).setErrStream(System.err); InputStream in=channel.getInputStream(); channel.connect(); byte[] tmp=new byte[1024]; while(true){ while(in.available()>0){ int i=in.read(tmp, 0, 1024); if(i<0)break; System.out.print(new String(tmp, 0, i)); } if(channel.isClosed()){ System.out.println("exit-status: "+channel.getExitStatus()); break; } try{Thread.sleep(1000);}catch(Exception ee){} } channel.disconnect(); sessionJSH.disconnect(); } catch(Exception e){ System.out.println(e); } %> |