1 23 package com.scalagent.joram.mom.dest.ftp; 24 25 import java.io.File ; 26 27 import net.sf.jftp.config.Settings; 28 import net.sf.jftp.net.BasicConnection; 29 import net.sf.jftp.net.ConnectionHandler; 30 import net.sf.jftp.net.ConnectionListener; 31 import net.sf.jftp.net.FtpConnection; 32 33 public class TransferImplJftp 34 implements TransferItf, ConnectionListener { 35 36 private boolean established = false; 37 38 private ConnectionHandler handler = new ConnectionHandler(); 41 42 public String getFile(String protocol, 43 String host, 44 int port, 45 String user, 46 String pass, 47 String remotePath, 48 String localPath, 49 String remoteFileName, 50 String localFileName, 51 String type, 52 long crc) throws Exception { 53 54 Settings.setProperty("jftp.disableLog","true"); 55 Settings.setProperty("jftp.enableMultiThreading","true"); 56 Settings.maxConnections = 5; 57 Settings.enableResuming = true; 58 59 FtpConnection con = null; 61 if (port > -1) 62 con = new FtpConnection(host,port,remotePath); 63 else 64 con = new FtpConnection(host); 65 66 con.addConnectionListener(this); 68 69 con.setConnectionHandler(handler); 71 72 con.login(user,pass); 74 75 while(!established) { 77 try { 78 Thread.sleep(10); 79 } catch(Exception exc) { 80 throw exc; 81 } 82 } 83 84 if (remotePath != null) 85 con.chdirRaw(remotePath); 86 87 if (localPath != null) 88 con.setLocalPath(localPath); 89 90 92 con.download(remoteFileName); 94 95 File file = new File (con.getLocalPath(),localFileName); 96 97 if (crc > 0 && crc != file.length()) 98 throw new Exception ("CRC ERROR."); 99 100 return file.getAbsolutePath(); 101 } 102 103 104 106 public void updateRemoteDirectory(BasicConnection con) {} 108 109 public void connectionInitialized(BasicConnection con) { 111 established = true; 112 } 113 114 public void updateProgress(String file, String type, long bytes) {} 116 117 public void connectionFailed(BasicConnection con, String why) {System.out.println("connection failed! " + why);} 119 120 public void actionFinished(BasicConnection con) {} 122 } 123 | Popular Tags |