1 10 package org.mmbase.module.builders.vwms; 11 12 import org.mmbase.util.*; 13 14 import org.mmbase.util.logging.Logger; 15 import org.mmbase.util.logging.Logging; 16 17 22 23 public class UnixCopy { 24 25 private static Logger log = Logging.getLoggerInstance(UnixCopy.class.getName()); 26 Execute exec=new Execute(); 27 String thisserver; 28 String dstpath,dstuser,dsthost; 29 String binpath; 30 31 public UnixCopy() { 32 setBinpath("/usr/local/bin"); 33 setUser("wwwtech"); 34 setHost("www.mmbase.org"); 35 setPath("/tmp/htdocs"); 36 } 37 38 39 public UnixCopy(String binpath) { 40 setBinpath(binpath); 41 setUser("wwwtech"); 42 setHost("www.mmbase.org"); 43 setPath("/tmp/htdocs"); 44 } 45 46 public UnixCopy(String binpath,String user) { 47 setBinpath(binpath); 48 setUser(user); 49 setHost("www.mmbase.org"); 50 setPath("/tmp/htdocs"); 51 } 52 53 public UnixCopy(String binpath,String user,String host) { 54 setBinpath(binpath); 55 setUser(user); 56 setHost(host); 57 setPath("/tmp/htdocs"); 58 } 59 60 public UnixCopy(String binpath,String user,String host,String path) { 61 setBinpath(binpath); 62 setUser(user); 63 setHost(host); 64 setPath(path); 65 } 66 67 public void copy(String base,String src,String dst) { 68 dsthost=dst; 69 copy(base,src); 70 } 71 72 public void copy(String base,String src) { 73 int last; 74 String path,res; 75 76 last=src.lastIndexOf('/'); 77 if (last!=-1) { 78 path=dstpath+src.substring(0,last); 79 mkdirs(path); 80 } 81 path=dstpath+src; 82 realcopy(base+src,path+".tmp"); 83 rename(path+".tmp",path); 84 } 85 86 87 public boolean mkdir(String path) { 88 boolean rtn=true;; 89 String res; 90 91 res=exec.execute(binpath+"/mkdir "+path+""); 92 if (log.isDebugEnabled()) { 93 log.debug("mkdir " + path + " : " + res); 94 } 95 96 rtn=res.length()<=0; 97 return(rtn); 98 } 99 100 public boolean mkdirs(String path) { 101 String res; 102 boolean rtn=true; 103 104 res=exec.execute(binpath+"/mkdir -p "+path+""); 105 if (log.isDebugEnabled()) { 106 log.debug("mkdirs " + path + " : " + res); 107 } 108 rtn=res.length()<=0; 109 return(rtn); 110 } 111 112 public boolean rename(String src,String dst) { 113 boolean rtn=true; 114 String res; 115 116 int pos=src.indexOf("("); 117 if (pos==-1) { 118 res=exec.execute(binpath+"/mv "+src+" "+dst+""); 119 } else { 120 res=exec.execute(binpath+"/mv \""+src+"\" \""+dst+"\""); 121 } 122 123 if (log.isDebugEnabled()) { 124 log.debug("rename " + src + "->" + dst + " : " + res); 125 } 126 rtn=res.length()<=0; 127 return(rtn); 128 } 129 130 public boolean realcopy(String src,String dst) { 131 String res; 132 boolean rtn=true; 133 res=exec.execute(binpath+"/cp "+src+" "+dst); 134 if (log.isDebugEnabled()) { 135 log.debug("copy " + src + "->" + dst + " : " + res); 136 } 137 rtn=res.length()<=0; 138 return (rtn); 139 } 140 141 public boolean remove(String path) { 142 String res; 143 boolean rtn=true; 144 145 res=exec.execute(binpath+"/rm -f "+path); 146 147 if (log.isDebugEnabled()) { 148 log.debug("remove " + path + " : " + res); 149 } 150 rtn=res.length()<=0; 151 return (rtn); 152 } 153 154 public boolean removedir(String path) { 155 String res; 156 boolean rtn=true; 157 158 res=exec.execute(binpath+"/rmdir "+path); 159 160 if (log.isDebugEnabled()) { 161 log.debug("removedir " + path + " : " + res); 162 } 163 rtn=res.length()<=0; 164 return (rtn); 165 } 166 167 168 169 public String getBinpath() { 170 return(binpath); 171 } 172 173 public String getPath() { 174 return(dstpath); 175 } 176 177 public String getHost() { 178 return(dsthost); 179 } 180 181 public String getUser() { 182 return(dstuser); 183 } 184 185 186 187 public void setBinpath(String path) { 188 binpath=path; 189 } 190 191 public void setPath(String path) { 192 dstpath=path; 193 } 194 195 public void setHost(String host) { 196 dsthost=host; 197 } 198 199 public void setUser(String user) { 200 dstuser=user; 201 } 202 203 204 public static void main(String args[]) { 205 SCPcopy scp=new SCPcopy(); 206 scp.copy(args[0],args[1],args[2]); 207 System.exit(0); 208 } 209 } 210 | Popular Tags |