spacer
spacer
site :
  home page
  news
  contact
  author

 
spacer
about FinJ :
  download
  online API
  mini-howto
  project-o-meter
  what's next ?

 
spacer
miscellaneous :
  contributors
  compatibility
  JUnit testing
  alternatives
  glossary

 
spacer
resources :
  summary@sf.net
  RFC-959
  LGPL license

 

finj - mini-howto

[ L A S T   U P D A T E   :   2022-03-03 ]

Introduction

This page will explain you how to get everything ready for a small demo of finj usage.

Once the simple demo is running, just edit it's source code to test more complexe features. Have a look to the API if you need ideas.

Do not hesitate to send me your comments or experiences with this mini-howto.

        -- javier
 


Installation

In order to get finj to work in your program, you need :

  • Java 2 Virtual Machine :
    Download, install, configure. Any version number larger that 1.2.x will make it.
    • Windows, Solaris and Linux users :
      download J2SE (Java 2 Plateform, Standard Edition) - for developpers - or JRE (Java 2 Runtime Machine) - virtual machine alone - from Sun Java official site (follow "products").
      Note that several other implementations are available, like IBM's, for example.
    • MacOS X users :
      have a Java 2 Virtual Machine installed by default.
    • MacOS 8.x, 9.x users :
      go to apple.com and have fun. If you get to understand something, just email me :)
  • finj :
    Sounds odd, doesn't it ? :)
    You can always get latest version of finj from sourceforge, on finj downloads page.
    finj is available in several packages :
    • finj-api :
      API doc alone.
      Doesn't contain any source code.
    • finj-bin :
      already compiled classes, ready to use !
      Will work with both J2SE and JRE.
    • finj-src :
      all source files, with a Makefile to recompile the whole project.
      Requires a full J2SE installation, JRE is not enough.
    • finj-i18n :
      internationalization files alone, for people that'd like to give a hand to the project.
      Contained in both finj-bin and finj-src packages.
  • setup :
    After downloading finj-bin_?.jar - where '?' is the version number - just copy it to the jre/lib/ext/ directory that can be found in the directory where you've installed the Java 2 Virtual Machine.

That's all, folks !
 


Simple demo code

If you've taken the steps above, compiling the demo program is just a question of typing at a prompt :

% javac FTPSimpleDemo.java

running it will be done by typing at a prompt :

% java FTPSimpleDemo <server> <user> <password>

where server, user and password match with valid FTP server name (or IP address) and valid user identification data for this server.

Contents of FTPSimpleDemo.java (for the lazy ones, here is the compiled class) :
 

import org.finj.FTPClient;

/**
 * Just a small demo class to show how to use <CODE>finj</CODE>'s 
 * in a really basic way.
 * 
 * @author Javier Iglesias -- jiglesias@users.sourceforge.net 
 * @version v1.0
 */
public class FTPSimpleDemo extends Object {

  /**
   * Constructs a new instance of <CODE>org.finj.FTPClient</CODE>, 
   * then tries to connect to the <CODE>server</CODE>, identifying  
   * the <CODE>user</CODE> with <CODE>password</CODE>, 
   * and finally prints to <CODE>System.out</CODE> the contents 
   * of the default directory (that MAY be EMPTY!).
   * 
   * @param server computer name or IP address to connect.
   * @param user   username to use when login.
   * @param passwd password to use when login.
   */
  public FTPSimpleDemo ( String server, 
                         String user, 
                         char[] password ) throws Exception {
    FTPClient client = new FTPClient();

    // connect to the server
    client.open(server);
    client.login(user, password);

    // get directory contents
    String[] names = client.getFileNames();
    System.out.println("Contents of directory '" + 
                       client.getWorkingDirectory() + 
                       "'");
    for ( int index = 0;
          index < names.length;
          index ++ ) {
      System.out.println("   NAME n°" + 
                         (index+1) + 
                         " -> " + 
                         names[index]);
    }

    // gracefully close connection
    client.close();
  }

  /**
   * Method that lauches the test. If no parameters are provided, it 
   * prints a "Usage" message.
   * 
   * @param args list of arguments provided on the command line.
   */
  public static void main ( String[] args ) throws Exception {
    if ( args.length < 3 ) {
      System.out.println("Usage : java FTPSimpleDemo <server> <user> <password>");
      return;
    }
    new FTPSimpleDemo(args[0], args[1], args[2].toCharArray());
  }
}
		            

 
 


forged on     written with     tested using
SourceForge Logo   JUnit logo   JUnit logo

project admin