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. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 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. Upload file to FTP server
2. Connect to FTP server
3. Get list of files from FTP server
4. Download file from FTP server
5. Delete file from FTP server
6. Implements a Java FTP client from socket and RFC
7. Graphical Ftp clientGraphical Ftp client
8. Ftp client demonstration
9. Ftp client gets server file size
10. Establish ftp connection
11. Use the FTP Client
12. Use the FTPClient: server file transfer
13. A simple Java tftp client
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.