00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package com.scalagent.joram.mom.dest.ftp;
00024
00025 import java.io.*;
00026 import java.net.*;
00027
00028 public class TransferImplRef
00029 implements TransferItf {
00030
00031 public String getFile(String protocol,
00032 String host,
00033 int port,
00034 String user,
00035 String pass,
00036 String remotePath,
00037 String localPath,
00038 String remoteFileName,
00039 String localFileName,
00040 String type,
00041 long crc) throws Exception {
00042
00043 StringBuffer sb = new StringBuffer();
00044
00045 sb.append("ftp://");
00046 sb.append(user);
00047 sb.append(":");
00048 sb.append(pass);
00049 sb.append("@");
00050 sb.append(host);
00051 if (port > -1) {
00052 sb.append(":");
00053 sb.append(port);
00054 }
00055 sb.append("/");
00056 if (remotePath != null)
00057 sb.append(remotePath + "/");
00058 sb.append(remoteFileName);
00059 sb.append(";type=");
00060 sb.append(type);
00061
00062 URL url = new URL(sb.toString());
00063
00064 URLConnection urlc = url.openConnection();
00065 InputStream is = urlc.getInputStream();
00066
00067 File file = new File(localPath,localFileName);
00068
00069 BufferedOutputStream bos = new BufferedOutputStream(
00070 new FileOutputStream(file));
00071
00072 int c = is.read();
00073 while (c != -1) {
00074 bos.write(c);
00075 c = is.read();
00076 }
00077 bos.flush();
00078 bos.close();
00079 is.close();
00080
00081 if (crc > 0 && crc != file.length())
00082 throw new Exception("CRC ERROR.");
00083
00084 return file.getAbsolutePath();
00085 }
00086 }