1 package org.apache.turbine.services.xmlrpc.util; 2 3 18 19 import java.net.URL ; 20 import java.util.Vector ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.turbine.services.xmlrpc.TurbineXmlRpc; 25 import org.apache.turbine.util.TurbineException; 26 27 36 public class FileTransfer 37 { 38 39 private static Log log = LogFactory.getLog(FileTransfer.class); 40 41 50 public static void send(String serverURL, 51 String sourceLocationProperty, 52 String sourceFileName, 53 String destinationLocationProperty, 54 String destinationFileName) 55 throws TurbineException 56 { 57 try 58 { 59 Vector params = new Vector (); 60 61 64 params.add(FileHandler.readFileContents( 65 sourceLocationProperty, sourceFileName)); 66 67 71 params.add(destinationLocationProperty); 72 73 76 params.add(destinationFileName); 77 78 Boolean b = (Boolean ) TurbineXmlRpc.executeRpc( 79 new URL (serverURL), "file.send", params); 80 81 } 82 catch (Exception e) 83 { 84 log.error("Error sending file to server:", e); 85 throw new TurbineException(e); 86 } 87 } 88 89 102 public static void send(String serverURL, 103 String username, 104 String password, 105 String sourceLocationProperty, 106 String sourceFileName, 107 String destinationLocationProperty, 108 String destinationFileName) 109 throws TurbineException 110 { 111 try 112 { 113 Vector params = new Vector (); 114 115 118 params.add(FileHandler.readFileContents( 119 sourceLocationProperty, sourceFileName)); 120 121 125 params.add(destinationLocationProperty); 126 127 130 params.add(destinationFileName); 131 132 Boolean b = (Boolean ) TurbineXmlRpc.executeAuthenticatedRpc( 133 new URL (serverURL), 134 username, 135 password, 136 "file.send", 137 params); 138 139 } 140 catch (Exception e) 141 { 142 log.error("Error sending file to server:", e); 143 throw new TurbineException(e); 144 } 145 } 146 147 157 public static void get(String serverURL, 158 String sourceLocationProperty, 159 String sourceFileName, 160 String destinationLocationProperty, 161 String destinationFileName) 162 throws TurbineException 163 { 164 165 try 166 { 167 Vector params = new Vector (); 168 169 173 params.add(sourceLocationProperty); 174 175 178 params.add(sourceFileName); 179 180 String fileContents = (String ) TurbineXmlRpc.executeRpc( 181 new URL (serverURL), "file.get", params); 182 183 187 FileHandler.writeFileContents(fileContents, 188 destinationLocationProperty, destinationFileName); 189 } 190 catch (Exception e) 191 { 192 log.error("Error getting file from server:", e); 193 throw new TurbineException(e); 194 } 195 } 196 197 209 public static void get(String serverURL, 210 String username, 211 String password, 212 String sourceLocationProperty, 213 String sourceFileName, 214 String destinationLocationProperty, 215 String destinationFileName) 216 throws TurbineException 217 { 218 219 try 220 { 221 Vector params = new Vector (); 222 223 227 params.add(sourceLocationProperty); 228 229 232 params.add(sourceFileName); 233 234 String fileContents = (String ) TurbineXmlRpc.executeAuthenticatedRpc( 235 new URL (serverURL), 236 username, 237 password, 238 "file.get", 239 params); 240 241 245 FileHandler.writeFileContents(fileContents, 246 destinationLocationProperty, destinationFileName); 247 } 248 catch (Exception e) 249 { 250 log.error("Error getting file from server:", e); 251 throw new TurbineException(e); 252 } 253 } 254 255 263 public static void remove(String serverURL, 264 String sourceLocationProperty, 265 String sourceFileName) 266 throws TurbineException 267 { 268 try 269 { 270 Vector params = new Vector (); 271 272 276 params.add(sourceLocationProperty); 277 278 281 params.add(sourceFileName); 282 283 TurbineXmlRpc.executeRpc(new URL (serverURL), "file.remove", params); 284 } 285 catch (Exception e) 286 { 287 log.error("Error removing file from server:", e); 288 throw new TurbineException(e); 289 } 290 } 291 292 302 public static void remove(String serverURL, 303 String username, 304 String password, 305 String sourceLocationProperty, 306 String sourceFileName) 307 throws TurbineException 308 { 309 try 310 { 311 Vector params = new Vector (); 312 313 317 params.add(sourceLocationProperty); 318 319 322 params.add(sourceFileName); 323 324 TurbineXmlRpc.executeAuthenticatedRpc(new URL (serverURL), 325 username, 326 password, 327 "file.remove", 328 params); 329 } 330 catch (Exception e) 331 { 332 log.error("Error removing file from server:", e); 333 throw new TurbineException(e); 334 } 335 } 336 } 337 | Popular Tags |