FTPCommon (Java Globus API)

org.globus.io.ftp
Class FTPCommon

java.lang.Object
  |
  +--org.globus.io.ftp.FTPCommon
Direct Known Subclasses:
FTPClient

public class FTPCommon
extends java.lang.Object

This class provides the basics for writting a simple ftp client. Provides support for passive data transfers and more.


Field Summary
static int ASCII
           
static int BINARY
           
protected  java.io.InputStream ftpin
           
protected  java.io.OutputStream ftpout
           
protected  java.lang.String host
           
static java.lang.String NLST
           
static int PERMANENT_NEGATIVE_REPLY
           
protected  int port
           
static int POSITIVE_COMPLETION_REPLY
           
static int POSITIVE_INTERMEDIATE_REPLY
           
static int POSITIVE_PRELIMINARY_REPLY
           
protected  RequestThread requestThread
           
static java.lang.String RETR
           
protected  java.net.Socket socket
           
static int TIMEOUT
           
static int TRANSIENT_NEGATIVE_REPLY
           
 
Constructor Summary
FTPCommon(java.lang.String host, int port)
          Connects to the ftp server on given host and port number.
 
Method Summary
 void abort()
           
 void authenticate()
          Performs anonymous authentication.
 void authenticate(java.lang.String user, java.lang.String pwd)
          Performs user authentication with specified user and password.
static void checkResponse(java.lang.String reply)
           
 void close()
          Closes the control channel connection
protected  void closeSocket()
           
 void connect()
          Establishes connection to the ftp server
 void disconnect()
           
 java.lang.String doCmd(java.lang.String cmd)
          Sends a simple command to the ftp server and returns the response.
 java.lang.String doCmd(java.lang.String cmd, java.lang.String args)
          Sends a simple command to the ftp server with an argument.
 void executeCommand(java.lang.String cmd, java.lang.String arg)
          Executes a ftp command and checks the reply for positive completion reply.
 java.net.Socket getControlSocket()
           
 java.lang.String getReply()
           
protected static java.lang.String getReply(java.io.InputStream in)
           
 RequestThread getRequestThread()
           
static int getResponse(java.lang.String reply)
           
static boolean isPositiveComplete(java.lang.String reply)
           
static boolean isPositivePreliminary(java.lang.String reply)
           
static boolean isReplyType(java.lang.String reply, int type)
           
protected static java.lang.String readLine(java.io.InputStream in)
           
 void sendFileCommand(java.lang.String cmd, java.lang.String arg)
          Executes a ftp command and checks the reply for positive preliminary reply.
 HostPort setPassiveMode()
           
 void setPort(HostPort hostPort)
           
 java.net.ServerSocket startDataChannel()
          Starts local server for data channel.
 java.net.ServerSocket startDataChannel(int port)
          Starts local server for data channel on a given port.
 java.net.Socket startPassiveDataChannel()
          Start passvide data channel on the ftp server and returns socket connected to it.
protected  void write(java.lang.String msg)
           
protected  void writeln(java.lang.String msg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT

public static final int TIMEOUT
See Also:
Constant Field Values

RETR

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

NLST

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

BINARY

public static final int BINARY
See Also:
Constant Field Values

ASCII

public static final int ASCII
See Also:
Constant Field Values

POSITIVE_PRELIMINARY_REPLY

public static final int POSITIVE_PRELIMINARY_REPLY
See Also:
Constant Field Values

POSITIVE_COMPLETION_REPLY

public static final int POSITIVE_COMPLETION_REPLY
See Also:
Constant Field Values

POSITIVE_INTERMEDIATE_REPLY

public static final int POSITIVE_INTERMEDIATE_REPLY
See Also:
Constant Field Values

TRANSIENT_NEGATIVE_REPLY

public static final int TRANSIENT_NEGATIVE_REPLY
See Also:
Constant Field Values

PERMANENT_NEGATIVE_REPLY

public static final int PERMANENT_NEGATIVE_REPLY
See Also:
Constant Field Values

socket

protected java.net.Socket socket

ftpout

protected java.io.OutputStream ftpout

ftpin

protected java.io.InputStream ftpin

host

protected java.lang.String host

port

protected int port

requestThread

protected RequestThread requestThread
Constructor Detail

FTPCommon

public FTPCommon(java.lang.String host,
                 int port)
          throws java.io.IOException,
                 FTPException
Connects to the ftp server on given host and port number.

Parameters:
host - hostname of the ftp server
port - port number of the ftp server
Method Detail

connect

public void connect()
             throws java.io.IOException,
                    FTPException
Establishes connection to the ftp server

java.io.IOException
FTPException

authenticate

public void authenticate()
                  throws java.io.IOException,
                         FTPException
Performs anonymous authentication.

java.io.IOException
FTPException

authenticate

public void authenticate(java.lang.String user,
                         java.lang.String pwd)
                  throws java.io.IOException,
                         FTPException
Performs user authentication with specified user and password.

Parameters:
user - username
pwd - user password
java.io.IOException
FTPException

startDataChannel

public java.net.ServerSocket startDataChannel()
                                       throws java.io.IOException,
                                              FTPException
Starts local server for data channel. The port number is automatically assigned. The information about the local server are sent to the ftp server (via PORT command)

Returns:
ServerSocket server
java.io.IOException
FTPException

startDataChannel

public java.net.ServerSocket startDataChannel(int port)
                                       throws java.io.IOException,
                                              FTPException
Starts local server for data channel on a given port. The information about the local server are sent to the ftp server (via PORT command)

Parameters:
port - port number
Returns:
ServerSocket server
java.io.IOException
FTPException

startPassiveDataChannel

public java.net.Socket startPassiveDataChannel()
                                        throws java.io.IOException,
                                               FTPException
Start passvide data channel on the ftp server and returns socket connected to it. Issues PASV command on the ftp server.

Returns:
socket data channel socket
java.io.IOException
FTPException

close

public void close()
Closes the control channel connection


closeSocket

protected void closeSocket()

doCmd

public java.lang.String doCmd(java.lang.String cmd)
                       throws java.io.IOException
Sends a simple command to the ftp server and returns the response.

Parameters:
cmd - ftp command
Returns:
reply reply string
java.io.IOException

doCmd

public java.lang.String doCmd(java.lang.String cmd,
                              java.lang.String args)
                       throws java.io.IOException
Sends a simple command to the ftp server with an argument. Returns the reply to the user.

Parameters:
cmd - ftp command
args - arguments
Returns:
reply reply string
java.io.IOException

readLine

protected static java.lang.String readLine(java.io.InputStream in)
                                    throws java.io.IOException
java.io.IOException

getReply

protected static java.lang.String getReply(java.io.InputStream in)
                                    throws java.io.IOException
java.io.IOException

getReply

public java.lang.String getReply()
                          throws java.io.IOException
java.io.IOException

writeln

protected void writeln(java.lang.String msg)
                throws java.io.IOException
java.io.IOException

write

protected void write(java.lang.String msg)
              throws java.io.IOException
java.io.IOException

executeCommand

public void executeCommand(java.lang.String cmd,
                           java.lang.String arg)
                    throws java.io.IOException,
                           FTPException
Executes a ftp command and checks the reply for positive completion reply.

Parameters:
cmd - ftp command
arg - arguments
Throws:
FTPException - if command was not executed correctly (error response different from POSITIVE_COMPLETEION_REPLY)
java.io.IOException

sendFileCommand

public void sendFileCommand(java.lang.String cmd,
                            java.lang.String arg)
                     throws java.io.IOException,
                            FTPException
Executes a ftp command and checks the reply for positive preliminary reply.

Parameters:
cmd - ftp command
arg - arguments
Throws:
FTPException - if command was not executed correctly (error response different from POSITIVE_PRELIMINARY_REPLY)
java.io.IOException

isPositiveComplete

public static boolean isPositiveComplete(java.lang.String reply)

isPositivePreliminary

public static boolean isPositivePreliminary(java.lang.String reply)

isReplyType

public static boolean isReplyType(java.lang.String reply,
                                  int type)

getResponse

public static int getResponse(java.lang.String reply)

checkResponse

public static void checkResponse(java.lang.String reply)
                          throws FTPException
FTPException

getControlSocket

public java.net.Socket getControlSocket()

getRequestThread

public RequestThread getRequestThread()

disconnect

public void disconnect()
                throws java.io.IOException,
                       FTPException
java.io.IOException
FTPException

abort

public void abort()
           throws java.io.IOException,
                  FTPException
java.io.IOException
FTPException

setPassiveMode

public HostPort setPassiveMode()
                        throws java.io.IOException,
                               FTPException
java.io.IOException
FTPException

setPort

public void setPort(HostPort hostPort)
             throws java.io.IOException,
                    FTPException
java.io.IOException
FTPException