com.enterprisedt.net.ftp
Class FTPControlSocket

java.lang.Object
  extended bycom.enterprisedt.net.ftp.FTPControlSocket

public class FTPControlSocket
extends java.lang.Object

Supports client-side FTP operations

Version:
$Revision: 1.10 $
Author:
Bruce Blackshaw

Field Summary
static int CONTROL_PORT
          The control port number for FTP
protected  java.net.Socket controlSock
          The underlying socket.
protected  java.io.PrintWriter log
          Output stream debug is written to, stdout by default
protected  java.io.BufferedReader reader
          The reader that reads control data from the control socket
protected  java.io.Writer writer
          The write that writes to the control socket
 
Constructor Summary
protected FTPControlSocket(java.net.Socket controlSock, java.io.PrintWriter log, int timeout)
          Constructs a new FTPControlSocket using the given Socket object.
 
Method Summary
protected  void closeLogStream()
          Close the log stream
 void logout()
          Quit this FTP session and clean up.
protected  FTPDataSocket newActiveDataSocket(int port)
          Constructs a new FTPDataSocket object (server mode) which will listen on the given port number.
protected  FTPDataSocket newPassiveDataSocket(java.lang.String remoteHost, int port)
          Constructs a new FTPDataSocket object (client mode) and connect to the given remote host and port number.
 java.lang.String sendCommand(java.lang.String command)
          Send a command to the FTP server and return the server's reply
protected  byte[] toByteArray(short value)
          Convert a short into a byte array
 FTPReply validateReply(java.lang.String reply, java.lang.String[] expectedReplyCodes)
          Validate the response the host has supplied against the expected reply.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTROL_PORT

public static final int CONTROL_PORT
The control port number for FTP

See Also:
Constant Field Values

log

protected java.io.PrintWriter log
Output stream debug is written to, stdout by default


controlSock

protected java.net.Socket controlSock
The underlying socket.


writer

protected java.io.Writer writer
The write that writes to the control socket


reader

protected java.io.BufferedReader reader
The reader that reads control data from the control socket

Constructor Detail

FTPControlSocket

protected FTPControlSocket(java.net.Socket controlSock,
                           java.io.PrintWriter log,
                           int timeout)
                    throws java.io.IOException,
                           FTPException
Constructs a new FTPControlSocket using the given Socket object.

Parameters:
controlSock - Socket to be used.
log - Logging writer to be used.
timeout - Timeout to be used.
Throws:
java.io.IOException - Thrown if no connection response could be read from the server.
FTPException - Thrown if the incorrect connection response was sent by the server.
Method Detail

logout

public void logout()
            throws java.io.IOException
Quit this FTP session and clean up.

Throws:
java.io.IOException

closeLogStream

protected void closeLogStream()
Close the log stream


toByteArray

protected byte[] toByteArray(short value)
Convert a short into a byte array

Parameters:
value - value to convert
Returns:
a byte array

newPassiveDataSocket

protected FTPDataSocket newPassiveDataSocket(java.lang.String remoteHost,
                                             int port)
                                      throws java.io.IOException
Constructs a new FTPDataSocket object (client mode) and connect to the given remote host and port number.

Parameters:
remoteHost - Remote host to connect to.
port - Remote port to connect to.
Returns:
A new FTPDataSocket object (client mode) which is connected to the given server.
Throws:
java.io.IOException - Thrown if no TCP/IP connection could be made.

newActiveDataSocket

protected FTPDataSocket newActiveDataSocket(int port)
                                     throws java.io.IOException
Constructs a new FTPDataSocket object (server mode) which will listen on the given port number.

Parameters:
port - Remote port to listen on.
Returns:
A new FTPDataSocket object (server mode) which is configured to listen on the given port.
Throws:
java.io.IOException - Thrown if an error occurred when creating the socket.

sendCommand

public java.lang.String sendCommand(java.lang.String command)
                             throws java.io.IOException
Send a command to the FTP server and return the server's reply

Returns:
reply to the supplied command
Throws:
java.io.IOException

validateReply

public FTPReply validateReply(java.lang.String reply,
                              java.lang.String[] expectedReplyCodes)
                       throws java.io.IOException,
                              FTPException
Validate the response the host has supplied against the expected reply. If we get an unexpected reply we throw an exception, setting the message to that returned by the FTP server

Parameters:
reply - the entire reply string we received
expectedReplyCodes - array of expected replies
Returns:
an object encapsulating the server's reply
Throws:
java.io.IOException
FTPException


Copyright (c) 2001-2004 Enterprise Distributed Technologies Ltd. All Rights Reserved.