Running the edtFTPj demo : Ftp « Network Protocol « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Network Protocol » FtpScreenshots 
Running the edtFTPj demo

/**
 
 *  Copyright (C) 2000-2004 Enterprise Distributed Technologies Ltd
 *
 *  www.enterprisedt.com
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Bug fixes, suggestions and comments should be sent to support@enterprisedt.com
 *
 *  Change Log:
 *
 *    $Log: Demo.java,v $
 *    Revision 1.6  2005/03/18 11:12:56  bruceb
 *    deprecated constructors
 *
 *    Revision 1.5  2005/02/04 12:30:26  bruceb
 *    print stack trace using logger
 *
 *    Revision 1.4  2004/06/25 12:34:55  bruceb
 *    logging added
 *
 *    Revision 1.3  2004/05/22 16:53:34  bruceb
 *    message listener added
 *
 *    Revision 1.2  2004/05/01 16:04:08  bruceb
 *    removed log stuff
 *
 *    Revision 1.1  2004/05/01 11:40:46  bruceb
 *    demo files
 *
 *
 */

import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPMessageCollector;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.Logger;

/**
 *  Simple test class for FTPClient
 *
 *  @author      Hans Andersen
 *  @author      Bruce Blackshaw
 */
public class Demo {
    
    /**
     *  Revision control id
     */
    private static String cvsId = "@(#)$Id: Demo.java,v 1.6 2005/03/18 11:12:56 bruceb Exp $";
    
    /**
     *  Log stream
     */
    private static Logger log = Logger.getLogger(Demo.class);

    /**
     * Standard main()
     
     @param args  standard args
     */
    public static void main(String[] args) {
               
        // we want remote host, user name and password
        if (args.length < 3) {
            usage();
            System.exit(1);
        }

        // assign args to make it clear
        String host = args[0];
        String user = args[1];
        String password = args[2];
        
        Logger.setLevel(Level.ALL);

        FTPClient ftp = null;

        try {
            // set up client    
            ftp = new FTPClient();
            ftp.setRemoteHost(host);
            FTPMessageCollector listener = new FTPMessageCollector();
            ftp.setMessageListener(listener);
            //ftp.setAutoPassiveIPSubstitution(true);
            
            // connect
            log.info("Connecting");
            ftp.connect();
            
             // login
            log.info("Logging in");
            ftp.login(user, password);

            // set up passive ASCII transfers
            log.debug("Setting up passive, ASCII transfers");
            ftp.setConnectMode(FTPConnectMode.PASV);
            ftp.setType(FTPTransferType.ASCII);

            // get directory and print it to console            
            log.debug("Directory before put:");
            String[] files = ftp.dir("."true);
            for (int i = 0; i < files.length; i++)
                log.debug(files[i]);

            // copy file to server 
            log.info("Putting file");
            ftp.put("test.txt""test.txt");

            // get directory and print it to console            
            log.debug("Directory after put");
            files = ftp.dir("."true);
            for (int i = 0; i < files.length; i++)
                log.debug(files[i]);

            // copy file from server
            log.info("Getting file");
            ftp.get("test.txt" ".copy""test.txt");

            // delete file from server
            log.info("Deleting file");
            ftp.delete("test.txt");

            // get directory and print it to console            
            log.debug("Directory after delete");
            files = ftp.dir(""true);
            for (int i = 0; i < files.length; i++)
                log.debug(files[i]);

            // Shut down client                
            log.info("Quitting client");
            ftp.quit();
            
            String messages = listener.getLog();
            log.debug("Listener log:");
            log.debug(messages);

            log.info("Test complete");
        catch (Exception e) {
            log.error("Demo failed", e);
        }
    }   
    
    /**
     *  Basic usage statement
     */
    public static void usage() {

        System.out.println("Usage: Demo remotehost user password");
    }

}

           
       
edtftpj-1.5.2.zip( 933 k)
Related examples in the same category
1. Implements a Java FTP client from socket and RFC
2. Graphical Ftp clientGraphical Ftp client
3. Ftp client demonstration
4. Ftp client gets server file size
5. Establish ftp connection
6. Use the FTP Client
7. Use the FTPClient: server file transfer
8. A simple Java tftp client
w__ww_._ja__v__a__2__s.c__o___m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.