1 package com.knowgate.dfs; 2 3 9 10 import java.io.IOException ; 11 import java.io.FileWriter ; 12 import java.io.PrintWriter ; 13 import java.io.PipedInputStream ; 14 import java.io.PipedOutputStream ; 15 16 import com.enterprisedt.net.ftp.FTPClient; 17 import com.enterprisedt.net.ftp.FTPException; 18 import com.enterprisedt.net.ftp.FTPTransferType; 19 import com.enterprisedt.net.ftp.FTPConnectMode; 20 21 import com.knowgate.debug.DebugFile; 22 23 public class FTPWorkerThread extends Thread { 24 private FTPClient oFTPC; 25 private boolean bLoged; 26 private PipedOutputStream oOutPipe; 27 private PipedInputStream oInPipe; 28 private FileWriter oFW; 29 private PrintWriter oPW; 30 private int iCmd; 31 private String sPar1; 32 private FileSystem oFileSys; 33 34 private int GET_PIPE = 16; 35 private int PUT_PIPE = 32; 36 private int MOV_PIPE = 64; 37 38 public FTPWorkerThread(String sHost, String sUser, String sPassword) throws FTPException,IOException { 39 bLoged = false; 40 oFileSys = null; 41 42 if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")"); 43 44 oFTPC = new FTPClient(sHost); 45 oFTPC.debugResponses(DebugFile.trace); 46 47 if (DebugFile.trace) { 48 oFW = new FileWriter ("/tmp/javatrc.txt", true); 49 oPW = new PrintWriter (oFW, true); 50 oFTPC.setLogStream(oPW); 51 DebugFile.writeln("FTPClient.login(" + sUser + "," + sPassword + ")"); 52 } 53 54 oFTPC.login(sUser, sPassword); 55 bLoged = true; 56 57 oFTPC.setConnectMode(FTPConnectMode.ACTIVE); 58 oFTPC.setType(FTPTransferType.BINARY); 59 } 61 63 public PipedInputStream getInputPipe () throws IOException { 64 return oInPipe; 65 } 67 69 public PipedOutputStream getOutputPipe () throws IOException { 70 return oOutPipe; 71 } 73 75 public void get (String sFile) throws IOException { 76 oOutPipe = new PipedOutputStream (); 77 sPar1 = sFile; 78 iCmd = GET_PIPE; 79 } 80 81 83 public void put (String sFile) throws IOException { 84 oInPipe = new PipedInputStream (); 85 sPar1 = sFile; 86 iCmd = PUT_PIPE; 87 } 89 91 public void move (String sFile) throws IOException { 92 oOutPipe = new PipedOutputStream (); 93 sPar1 = sFile; 94 iCmd = MOV_PIPE; 95 } 96 97 99 public void connect (PipedInputStream oStrm) throws IOException { 100 if (DebugFile.trace) DebugFile.writeln("FTPWorkerThread.connect([PipedInputStream])"); 101 oOutPipe.connect (oStrm); 102 } 104 106 public void connect (PipedOutputStream oStrm) throws IOException { 107 if (DebugFile.trace) DebugFile.writeln("FTPWorkerThread.connect([PipedOutputStream])"); 108 oInPipe.connect (oStrm); 109 } 111 113 public void chdir (String sPath) throws FTPException,IOException { 114 oFTPC.chdir(sPath); 115 } 117 119 public void run() { 120 try { 121 if (GET_PIPE==iCmd) { 122 if (DebugFile.trace) DebugFile.writeln("oFTPC.get([PipedOutputStream]," + sPar1 + ")"); 123 oFTPC.get(oOutPipe, sPar1); 124 oFTPC.quit(); 125 bLoged=false; 126 } 127 else if (PUT_PIPE==iCmd) { 128 if (DebugFile.trace) DebugFile.writeln("oFTPC.put([PipedInputStream]," + sPar1 + ")"); 129 oFTPC.put(oInPipe, sPar1); 130 oFTPC.quit(); 131 bLoged=false; 132 } 133 else if (MOV_PIPE==iCmd) { 134 if (DebugFile.trace) DebugFile.writeln("oFTPC.get([PipedOutputStream]," + sPar1 + ")"); 135 oFTPC.get(oOutPipe, sPar1); 136 if (DebugFile.trace) DebugFile.writeln("oFTPC.delete([PipedOutputStream]," + sPar1 + ")"); 137 oFTPC.delete(sPar1); 138 oFTPC.quit(); 139 bLoged=false; 140 } 141 } 142 catch (FTPException ftpe) { 143 if (DebugFile.trace) DebugFile.writeln("FTPException:" + ftpe.getMessage()); 144 } 145 catch (IOException ioe) { 146 if (DebugFile.trace) DebugFile.writeln("IOException:" + ioe.getMessage()); 147 } 148 } } | Popular Tags |