com.citycolor.net.ftp
Class FTPHandler

java.lang.Object
  extended by com.citycolor.net.ftp.FTPHandler

public class FTPHandler
extends java.lang.Object

FTPHandler provides the highest level API for controlling the FTP session. Developers should subclass it to add extra commands, such as getting a remote directory list, or erasing a remote file. Future versions might include such commands directly in this class. There shouldn't be any backwards compatibility problems as new operations are added here since methods in this class are intended to be atomic transactions and should be written that way.

Here's a snippet showing how to use it.

      File filePath = new File( "sample.fil" );
      String textFileName = "sample.txt";
      String text = "Some sample text";
      String domainName = "some.ftpserver.com";
      String userName = "anonymous";
      String password = "name@mailserver.com";

      try
      {
          FTPHandler ftpHandler = new FTPHandler( new FTPControlConnection( InetAddress.getByName( domainName )));
          System.out.println( ftpHandler.controlConnection.getServerConnectString() );
          System.out.println( ftpHandler.login( userName, password, null ) );
          ftpHandler.sendText( text, textFileName, true );
          ftpHandler.sendFile( filePath, filePath.getName(), true );
      }
      catch ( FTPExecuteException ftpException )
      {
          System.err.println( ftpException.getResponse().userString() );
      }
      catch ( IOException ioException )
      {
          System.err.println( ioException );
      }
      controlConnection.commSocket.close();
 

Author:
Sebastian E. Ferreyra Pons

Field Summary
static java.lang.String ACCT
           
static java.lang.String CDUP
           
 FTPControlConnection controlConnection
           
static java.lang.String CWD
           
static java.lang.String MODE
           
static java.lang.String NOOP
           
static java.lang.String PASS
           
static java.lang.String PASV
           
static java.lang.String PORT
           
static java.lang.String PWD
           
static java.lang.String QUIT
           
static java.lang.String RETR
           
static java.lang.String STOR
           
static java.lang.String STRU
           
static java.lang.String TYPE
           
static java.lang.String USER
           
 
Constructor Summary
FTPHandler(FTPControlConnection ctrlConnection)
           
 
Method Summary
 java.lang.String login(java.lang.String user, java.lang.String pass, java.lang.String acct)
          Logs the user in the server and returns the welcome message if succesful.
 void sendFile(java.io.File filePath, java.lang.String remoteFileName, boolean usePassiveMode)
          Send's a file to the server.
 void sendText(java.lang.String text, java.lang.String remoteFileName, boolean usePassiveMode)
          Send's a text string to the server, storing it remotely as a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

controlConnection

public final FTPControlConnection controlConnection

ACCT

public static final java.lang.String ACCT
See Also:
Constant Field Values

CDUP

public static final java.lang.String CDUP
See Also:
Constant Field Values

CWD

public static final java.lang.String CWD
See Also:
Constant Field Values

MODE

public static final java.lang.String MODE
See Also:
Constant Field Values

NOOP

public static final java.lang.String NOOP
See Also:
Constant Field Values

PASS

public static final java.lang.String PASS
See Also:
Constant Field Values

PASV

public static final java.lang.String PASV
See Also:
Constant Field Values

PORT

public static final java.lang.String PORT
See Also:
Constant Field Values

PWD

public static final java.lang.String PWD
See Also:
Constant Field Values

QUIT

public static final java.lang.String QUIT
See Also:
Constant Field Values

RETR

public static final java.lang.String RETR
See Also:
Constant Field Values

STOR

public static final java.lang.String STOR
See Also:
Constant Field Values

STRU

public static final java.lang.String STRU
See Also:
Constant Field Values

TYPE

public static final java.lang.String TYPE
See Also:
Constant Field Values

USER

public static final java.lang.String USER
See Also:
Constant Field Values
Constructor Detail

FTPHandler

public FTPHandler(FTPControlConnection ctrlConnection)
Method Detail

login

public java.lang.String login(java.lang.String user,
                              java.lang.String pass,
                              java.lang.String acct)
                       throws FTPExecuteException,
                              java.io.IOException
Logs the user in the server and returns the welcome message if succesful.

Parameters:
user - The Username
pass - The Password
acct - The Account name
Returns:
The server's welcome message.
Throws:
FTPExecuteException
java.io.IOException

sendFile

public void sendFile(java.io.File filePath,
                     java.lang.String remoteFileName,
                     boolean usePassiveMode)
              throws FTPExecuteException,
                     java.io.IOException
Send's a file to the server.

Parameters:
filePath - The file path.
remoteFileName - The name the file will have on the server.
usePassiveMode - True if the operation should proceed in passive mode.
Throws:
FTPExecuteException
java.io.IOException

sendText

public void sendText(java.lang.String text,
                     java.lang.String remoteFileName,
                     boolean usePassiveMode)
              throws FTPExecuteException,
                     java.io.IOException
Send's a text string to the server, storing it remotely as a file.

Parameters:
text - The text.
remoteFileName - The name the file will have on the server.
usePassiveMode - True if the operation should proceed in passive mode.
Throws:
FTPExecuteException
java.io.IOException


Copyright 1999-2004 Sebastian E. Ferreyra Pons. All Rights Reserved.