Package com.enterprisedt.net.ftp

Examples of com.enterprisedt.net.ftp.FTPClient$DirectoryCallbackImpl


     *
     * @return          connected FTPClient
     * @throws Exception
     */
    public FTPClientInterface connect() throws Exception {
        FTPClient ftp = createClient();
        ftp.connect()
        ftp.login(user, password);
        return ftp;
    }
View Full Code Here


        return ftp;
    }
   
    private FTPClient createClient() throws Exception {
     // connect
        FTPClient ftp = null;
        if (!useDeprecatedConstructors) {
            ftp = new FTPClient();
            ftp.setRemoteHost(host);
            ftp.setTimeout(timeout);
           
        }
        else {
            ftp = new FTPClient(host, FTPControlSocket.CONTROL_PORT, timeout);
        }
        ftp.setAutoPassiveIPSubstitution(autoPassiveIPSubstitution);
        ftp.setConnectMode(connectMode);
        ftp.setDetectTransferMode(true);
        if (!strictReplies) {
            log.warn("Strict replies not enabled");
            ftp.setStrictReturnCodes(false);
        }
        return ftp;
    }
View Full Code Here

     *
     * @return          connected FTPClientInterface
     * @throws Exception
     */
    public FTPClientInterface connect(int lowest, int highest) throws Exception {
        FTPClient ftp = createClient();
        ftp.setActivePortRange(lowest, highest);
        ftp.connect()
        ftp.login(user, password);
        return ftp;
    }
View Full Code Here

        ftp.login(user, password);
        return ftp;
    }
   
    public void reconnect(FTPClientInterface ftp) throws Exception {
        FTPClient client = (FTPClient)ftp;
        client.connect();
        client.login(user, password);
    }
View Full Code Here

            String directory = args[4];
            String mode = args[5];
            String connMode = args[6];

            // connect and test supplying port no.
            FTPClient ftp = new FTPClient();
            ftp.setControlEncoding("UTF-8");
            ftp.setRemoteHost(host);
            ftp.setRemotePort(21);
            ftp.connect();
            ftp.login(user, password);
            ftp.quote("LANG da-DK", new String[] { "200" });
//            ftp.dirDetails(".");
            ftp.chdir("test");
            ftp.quit();
            if (true)
              return;

            // connect again
            ftp = new FTPClient();
            ftp.setRemoteHost(host);

            ftp.login(user, password);
           
            ftp.dir(".", false);

            // binary transfer
            if (mode.equalsIgnoreCase("BINARY")) {
                ftp.setType(FTPTransferType.BINARY);
            }
            else if (mode.equalsIgnoreCase("ASCII")) {
                ftp.setType(FTPTransferType.ASCII);
            }
            else {
                System.out.println("Unknown transfer type: " + args[5]);
                System.exit(-1);
            }

            // PASV or active?
            if (connMode.equalsIgnoreCase("PASV")) {
                ftp.setConnectMode(FTPConnectMode.PASV);
            }
            else if (connMode.equalsIgnoreCase("ACTIVE")) {
                ftp.setConnectMode(FTPConnectMode.ACTIVE);
            }
            else {
                System.out.println("Unknown connect mode: " + args[6]);
                System.exit(-1);
            }

            // change dir
            ftp.chdir(directory);

            // put a local file to remote host
            ftp.put(filename, filename);

            // get bytes
            byte[] buf = ftp.get(filename);
            System.out.println("Got " + buf.length + " bytes");

            // append local file
            try {
                ftp.put(filename, filename, true);
            }
            catch (FTPException ex) {
                System.out.println("Append failed: " + ex.getMessage());
            }

            // get bytes again - should be 2 x
            buf = ftp.get(filename);
            System.out.println("Got " + buf.length + " bytes");

            // rename
            ftp.rename(filename, filename + ".new");

            // get a remote file - the renamed one
            ftp.get(filename + ".tst", filename + ".new");

            // ASCII transfer
            ftp.setType(FTPTransferType.ASCII);

            // test that list() works
            String[] listing = ftp.dir(".");
            for (int i=0; i<listing.length; i++)
              System.out.println(listing[i]);

            // test that dir() works in full mode
            String[] listings = ftp.dir(".", true);
            for (int i = 0; i < listings.length; i++)
                System.out.println(listings[i]);

            // try system()
            System.out.println(ftp.system());

            // try pwd()
            System.out.println(ftp.pwd());

            ftp.quit();
        }
        catch (Exception ex) {
            System.out.println("Caught exception: " + ex.getMessage());
        }
    }
View Full Code Here

    bLoged = false;
    oFileSys = null;

    if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");

    oFTPC = new FTPClient(sHost);
    oFTPC.debugResponses(DebugFile.trace);

    if (DebugFile.trace) {
      oFW = new FileWriter("/tmp/javatrc.txt", true);
      oPW = new PrintWriter(oFW, true);
View Full Code Here

  private void copyFTPToFTP(String sSource, String sTarget)
    throws FTPException,IOException {

    String sSourceHost, sTargetHost, sSourcePath, sTargetPath, sSourceFile, sTargetFile, sTempName;
    FTPWorkerThread oReader,oWriter;
    FTPClient oFTPC;

    if (DebugFile.trace) {
      DebugFile.writeln("Begin FileSystem.copyFTPToFTP(" + sSource + "," + sTarget + ")");
      DebugFile.incIdent();
    }

    splitURI(sSource);
    sSourceHost = sHost;
    sSourcePath = sPath;
    if (!sSourcePath.endsWith("/")) sSourcePath+="/";
    sSourceFile = sFile;

    splitURI(sTarget);
    sTargetHost = sHost;
    sTargetPath = sPath;
    if (!sTargetPath.endsWith("/")) sTargetPath+="/";
    sTargetFile = sFile;

    if (sSourceHost.equals(sTargetHost) && (OS!=OS_PUREJAVA)) {
      sTempName = Gadgets.generateUUID();

      oFTPC = new FTPClient(sTargetHost);
      oFTPC.login(user(), password());

      if (DebugFile.trace)DebugFile.writeln("FTPClient.site(exec cp " + sSourcePath + sSourceFile + " " + sTargetPath + sTargetFile);
      oFTPC.rename(sSourcePath + sSourceFile, sSourcePath + sTempName );
      oFTPC.site("exec cp " + sSourcePath + sTempName + " " + sTargetPath + sTargetFile);
      oFTPC.rename(sSourcePath + sTempName, sSourcePath + sSourceFile);
      oFTPC.quit();
    }
    else {
      oReader = new FTPWorkerThread(sSourceHost, sUsr, sPwd);
      oWriter = new FTPWorkerThread(sTargetHost, sUsr, sPwd);
View Full Code Here

  // ---------------------------------------------------------------------------

  private void copyFileToFTP(String sSource, String sTarget) throws Exception,IOException {
    boolean bFTPSession = false;

    FTPClient oFTPC = null;

    splitURI(sTarget);

    try {
      if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");
      oFTPC = new FTPClient(sHost);
      if (DebugFile.trace) DebugFile.writeln("FTPClient.login(" + sUsr + "," + sPwd + ")");
      oFTPC.login(sUsr, sPwd);
      bFTPSession = true;
      if (DebugFile.trace) DebugFile.writeln("FTPClient.chdir(" + sPath + ")");
      oFTPC.chdir(sPath);
      if (DebugFile.trace) DebugFile.writeln("FTPClient.put(" + sSource + "," + sFile + ",false)");
      oFTPC.setType(FTPTransferType.BINARY);
      oFTPC.put(sSource, sFile, false);

    } catch (FTPException ftpe) {
      throw new Exception(ftpe.getMessage(), ftpe.getCause());
    }
    finally {
      if (DebugFile.trace) DebugFile.writeln("FTPClient.quit()");
      if (bFTPSession) oFTPC.quit();
    }

  } // copyFileToFTP()
View Full Code Here

  private void copyFTPToFile(String sSource, String sTarget)
    throws Exception,IOException {

    boolean bFTPSession = false;

    FTPClient oFTPC = null;

    splitURI(sSource);

    try {
      if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");
      oFTPC = new FTPClient(sHost);
      if (DebugFile.trace) DebugFile.writeln("FTPClient.login(" + sUsr + "," + sPwd + ")");
      oFTPC.login(sUsr, sPwd);
      bFTPSession = true;
      if (DebugFile.trace) DebugFile.writeln("FTPClient.chdir(" + sPath + ")");
      oFTPC.chdir(sPath);
      if (DebugFile.trace) DebugFile.writeln("FTPClient.get(" + sTarget + "," + sFile + ",false)");
      oFTPC.setType(FTPTransferType.BINARY);
      oFTPC.get(sTarget, sFile);

    } catch (FTPException ftpe) {
      throw new Exception(ftpe.getMessage(), ftpe.getCause());
    }
    finally {
      if (DebugFile.trace) DebugFile.writeln("FTPClient.quit()");
      if (bFTPSession) oFTPC.quit();
    }

  } // copyFileToFTP()
View Full Code Here

  if (sSourceURI.startsWith("file://")) {
    bExists = new File(sSourceURI.substring(7)).exists();   
  } else if (sSourceURI.startsWith("ftp://")) {
      boolean bFTPSession = false;
      FTPClient oFTPC = null;
      splitURI(sSourceURI);
    String[] aFiles = null;
    try {
        if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");
        oFTPC = new FTPClient(sHost);
        if (DebugFile.trace) DebugFile.writeln("FTPClient.login(" + sUsr + "," + sPwd + ")");
        oFTPC.login(sUsr, sPwd);
        bFTPSession = true;
        if (DebugFile.trace) DebugFile.writeln("FTPClient.dir(" + sPath + ")");
        aFiles = oFTPC.dir(sPath);
      oFTPC.quit();
    } catch (FTPException ftpe) {
      throw new IOException(ftpe.getMessage());
    }
    if (aFiles!=null) {
      int nFiles = aFiles.length;
View Full Code Here

TOP

Related Classes of com.enterprisedt.net.ftp.FTPClient$DirectoryCallbackImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.