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.File;
00026
00027 import net.sf.jftp.config.Settings;
00028 import net.sf.jftp.net.BasicConnection;
00029 import net.sf.jftp.net.ConnectionHandler;
00030 import net.sf.jftp.net.ConnectionListener;
00031 import net.sf.jftp.net.FtpConnection;
00032
00033 public class TransferImplJftp
00034 implements TransferItf, ConnectionListener {
00035
00036 private boolean established = false;
00037
00038
00039
00040 private ConnectionHandler handler = new ConnectionHandler();
00041
00042 public String getFile(String protocol,
00043 String host,
00044 int port,
00045 String user,
00046 String pass,
00047 String remotePath,
00048 String localPath,
00049 String remoteFileName,
00050 String localFileName,
00051 String type,
00052 long crc) throws Exception {
00053
00054 Settings.setProperty("jftp.disableLog","true");
00055 Settings.setProperty("jftp.enableMultiThreading","true");
00056 Settings.maxConnections = 5;
00057 Settings.enableResuming = true;
00058
00059
00060 FtpConnection con = null;
00061 if (port > -1)
00062 con = new FtpConnection(host,port,remotePath);
00063 else
00064 con = new FtpConnection(host);
00065
00066
00067 con.addConnectionListener(this);
00068
00069
00070 con.setConnectionHandler(handler);
00071
00072
00073 con.login(user,pass);
00074
00075
00076 while(!established) {
00077 try {
00078 Thread.sleep(10);
00079 } catch(Exception exc) {
00080 throw exc;
00081 }
00082 }
00083
00084 if (remotePath != null)
00085 con.chdirRaw(remotePath);
00086
00087 if (localPath != null)
00088 con.setLocalPath(localPath);
00089
00090
00091
00092
00093 con.download(remoteFileName);
00094
00095 File file = new File(con.getLocalPath(),localFileName);
00096
00097 if (crc > 0 && crc != file.length())
00098 throw new Exception("CRC ERROR.");
00099
00100 return file.getAbsolutePath();
00101 }
00102
00103
00104
00105
00106
00107 public void updateRemoteDirectory(BasicConnection con) {}
00108
00109
00110 public void connectionInitialized(BasicConnection con) {
00111 established = true;
00112 }
00113
00114
00115 public void updateProgress(String file, String type, long bytes) {}
00116
00117
00118 public void connectionFailed(BasicConnection con, String why) {System.out.println("connection failed! " + why);}
00119
00120
00121 public void actionFinished(BasicConnection con) {}
00122 }