1 10 package org.mmbase.module.builders.vwms; 11 12 import org.mmbase.util.*; 13 import org.mmbase.util.logging.*; 14 15 28 public class SCPcopy { 29 30 33 Execute exec=new Execute(); 34 37 String thisserver; 38 41 String dstpath; 42 46 String dstuser; 47 50 String dsthost; 51 54 String sshpath; 55 56 private static Logger log = Logging.getLoggerInstance(SCPcopy.class.getName()); 58 59 63 public SCPcopy() { 64 setSSHpath("/usr/local/bin"); 65 setUser("vpro"); 66 setHost("vpro.omroep.nl"); 67 setPath("/bigdisk/htdocs"); 68 } 69 70 75 public SCPcopy(String sshpath) { 76 setSSHpath(sshpath); 77 setUser("vpro"); 78 setHost("vpro.omroep.nl"); 79 setPath("/bigdisk/htdocs"); 80 } 81 82 88 public SCPcopy(String sshpath,String user) { 89 setSSHpath(sshpath); 90 setUser(user); 91 setHost("vpro.omroep.nl"); 92 setPath("/bigdisk/htdocs"); 93 } 94 95 102 public SCPcopy(String sshpath,String user,String host) { 103 setSSHpath(sshpath); 104 setUser(user); 105 setHost(host); 106 setPath("/bigdisk/htdocs"); 107 } 108 109 116 public SCPcopy(String sshpath,String user,String host,String path) { 117 setSSHpath(sshpath); 118 setUser(user); 119 setHost(host); 120 setPath(path); 121 } 122 123 130 public void copy(String base,String src,String dst) { 131 dsthost=dst; 132 copy(base,src); 133 } 134 135 141 public void copy(String base,String src) { 142 int last; 143 String path,res; 144 145 last=src.lastIndexOf('/'); 146 147 if (last!=-1) { 149 path=dstpath+src.substring(0,last); 150 mkdirs(path); 152 } 153 path=dstpath+src; 155 realcopy(base+src,path+".tmp"); 156 rename(path+".tmp",path); 157 } 158 159 164 public boolean mkdir(String path) { 165 String res; 166 res=exec.execute(sshpath+"/ssh -q -l "+dstuser+" "+dsthost+" mkdir "+path+""); 167 log.debug("SCPcopy -> mkdir "+path+" : "+res); 168 return res.length()<=0; 169 } 170 171 176 public boolean mkdirs(String path) { 177 String res; 178 res=exec.execute(sshpath+"/ssh -q -l "+dstuser+" "+dsthost+" mkdir -p "+path+""); 179 log.debug("SCPcopy -> mkdirs "+path+" : "+res); 180 return res.length()<=0; 181 } 182 183 189 public boolean rename(String src,String dst) { 190 String res; 191 int pos=src.indexOf("("); if (pos==-1) { 193 res=exec.execute(sshpath+"/ssh -q -l "+dstuser+" "+dsthost+" mv "+src+" "+dst+""); 194 } else { 195 res=exec.execute(sshpath+"/ssh -q -l "+dstuser+" "+dsthost+" mv \""+src+"\" \""+dst+"\""); 196 } 197 198 log.debug("SCPcopy -> rename "+src+"->"+dst+" : "+res); 199 return res.length()<=0; 200 } 201 202 209 public boolean realcopy(String src,String dst) { 210 String res; 211 int pos=src.indexOf("("); if (pos==-1) { 213 res=exec.execute(sshpath+"/scp -B -A -q "+src+" "+dstuser+"@"+dsthost+":"+dst); 214 } else { 215 res=exec.execute(sshpath+"/scp -B -A -q "+src+" "+dstuser+"@"+dsthost+":\""+dst+"\""); 216 } 217 218 log.service("SCPcopy -> copy "+src+"->"+dst+" : "+res); 219 return res.length()<=0; 220 } 221 222 227 public boolean remove(String path) { 228 String res; 229 res=exec.execute(sshpath+"/ssh -q -l "+dstuser+" "+dsthost+" rm -f "+path); 230 log.debug("SCPcopy -> remove "+path+" : "+res); 231 return res.length()<=0; 232 } 233 234 239 public boolean removedir(String path) { 240 String res; 241 res=exec.execute(sshpath+"/ssh -q -l "+dstuser+" "+dsthost+" rmdir "+path); 242 log.debug("SCPcopy -> removedir "+path+" : "+res); 243 return res.length()<=0; 244 } 245 246 249 public String getSSHpath() { 250 return(sshpath); 251 } 252 253 256 public String getPath() { 257 return(dstpath); 258 } 259 260 263 public String getHost() { 264 return(dsthost); 265 } 266 267 270 public String getUser() { 271 return(dstuser); 272 } 273 274 275 276 279 public void setSSHpath(String path) { 280 sshpath=path; 281 } 282 283 286 public void setPath(String path) { 287 dstpath=path; 288 } 289 290 293 public void setHost(String host) { 294 dsthost=host; 295 } 296 297 300 public void setUser(String user) { 301 dstuser=user; 302 } 303 304 311 public static void main(String args[]) { 312 SCPcopy scp=new SCPcopy(); 313 scp.copy(args[0],args[1],args[2]); 314 System.exit(0); 315 } 316 } 317 | Popular Tags |