Package com.enterprisedt.net.ftp

Examples of com.enterprisedt.net.ftp.FTPClient


      m_details.debug();
     
      System.out.println("TransferEdtftpj::open(), setting properties");
     
      try{
        m_ftp = new FTPClient();
        m_ftp.setRemoteHost(m_details.getServer());
        m_ftp.setRemotePort(m_details.getPort());
        m_ftp.connect();
       
        System.out.println("TransferEdtftpj::open(), trying to connect");
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(host, 21);
            ftp.login(user, password);
            ftp.quit();

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

            ftp.login(user, password);

            // 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.list(".");
            System.out.println(listing);

            // 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 (IOException ex) {
            System.out.println("Caught exception: " + ex.getMessage());
        }
        catch (FTPException ex) {
View Full Code Here

     * @return          connected FTPClient
     * @throws Exception
     */
    public FTPClientInterface connect() 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);
        }
        ftp.connect()
        ftp.login(user, password);
        return ftp;
    }
View Full Code Here

TOP

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

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.