import org.finj.FTPClient;
/**
* Just a small demo class to show how to use finj'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 org.finj.FTPClient,
* then tries to connect to the server, identifying
* the user with password,
* and finally prints to System.out 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 ");
return;
}
new FTPSimpleDemo(args[0], args[1], args[2].toCharArray());
}
}