1 23 package com.scalagent.joram.mom.dest.ftp; 24 25 import java.io.*; 26 import java.net.*; 27 28 public class TransferImplRef 29 implements TransferItf { 30 31 public String getFile(String protocol, 32 String host, 33 int port, 34 String user, 35 String pass, 36 String remotePath, 37 String localPath, 38 String remoteFileName, 39 String localFileName, 40 String type, 41 long crc) throws Exception { 42 43 StringBuffer sb = new StringBuffer (); 44 45 sb.append("ftp://"); 46 sb.append(user); 47 sb.append(":"); 48 sb.append(pass); 49 sb.append("@"); 50 sb.append(host); 51 if (port > -1) { 52 sb.append(":"); 53 sb.append(port); 54 } 55 sb.append("/"); 56 if (remotePath != null) 57 sb.append(remotePath + "/"); 58 sb.append(remoteFileName); 59 sb.append(";type="); 60 sb.append(type); 61 62 URL url = new URL(sb.toString()); 63 64 URLConnection urlc = url.openConnection(); 65 InputStream is = urlc.getInputStream(); 66 67 File file = new File(localPath,localFileName); 68 69 BufferedOutputStream bos = new BufferedOutputStream( 70 new FileOutputStream(file)); 71 72 int c = is.read(); 73 while (c != -1) { 74 bos.write(c); 75 c = is.read(); 76 } 77 bos.flush(); 78 bos.close(); 79 is.close(); 80 81 if (crc > 0 && crc != file.length()) 82 throw new Exception ("CRC ERROR."); 83 84 return file.getAbsolutePath(); 85 } 86 } 87 | Popular Tags |