com.Prominic.jFTPd
Class FTPConnection.ConnectionState

java.lang.Object
  extended by com.Prominic.jFTPd.FTPConnection.ConnectionState
Enclosing class:
FTPConnection

 class FTPConnection.ConnectionState
extends java.lang.Object

This class represents the current state of the connection - whether the control connection is secured or not - whether the data connection is secured or not It embeds the socket and also handles the communication with the server because it knows to use a SSL or a plain text socket.

Author:
VIulian

Field Summary
private  boolean ccPlainText
           
private  boolean dataPlainText
           
private  java.net.Socket dataSock
           
private  boolean hasPbsz
           
private  java.io.BufferedReader in
           
private  CRLFPrintWriter out
           
private  int protectionBufferSize
           
private  java.net.Socket sock
           
private  javax.net.ssl.SSLSocket sslDataSock
           
private  javax.net.ssl.SSLSocket sslsock
           
private  boolean useProtectedDC
           
 
Constructor Summary
FTPConnection.ConnectionState(java.net.Socket plaintext)
          Initialises the state using a plain text socket.
 
Method Summary
 void closeSockets()
          Closes the sockets streams and then the sockets.
 void downgradeCCtoPlainText()
          Closes the SSL layer on top of the command channel but keeps the CC channel in clear mode.
 java.io.BufferedReader getCCInputBuffer()
          Returns the input buffer for the control connection
 CRLFPrintWriter getCCOutputBuffer()
          Returns the output buffer for the control connection
 java.net.Socket getClientSocket()
          Returns a data connection socket, SSL if needed.
 java.net.Socket getCurrentSocket()
          Gets the current active socket (either SSL or not)
 java.io.InputStream getDataInputStream()
          Gets the data input stream, either SSL or not.
 java.io.OutputStream getDataOutputStream()
          Gets the data output stream, either SSL or not.
 boolean hasIssuedPBSZ()
          Check if a protection buffer size has been set to something 0 or greater;
 void init()
          Initialises the internal state.
 boolean isCCPlainText()
          Returns true if the control connection is plain text
 boolean isCCSecure()
          Returns whether the current control connection is secured.
 void sendReply(java.lang.String message)
          Sends a reply to the client, using the current output stream (either SSL or not)
 void setProtectionBuffer(int size)
          Sets the protection buffer to the given size.
 void setProtectionLevel(java.lang.String level)
          Sets the protection level of the communication channel.
 boolean upgradeCCToSSL()
          Upgrades the control connection to use SSL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sock

private java.net.Socket sock

dataSock

private java.net.Socket dataSock

sslsock

private javax.net.ssl.SSLSocket sslsock

sslDataSock

private javax.net.ssl.SSLSocket sslDataSock

ccPlainText

private boolean ccPlainText

dataPlainText

private boolean dataPlainText

out

private CRLFPrintWriter out

in

private java.io.BufferedReader in

protectionBufferSize

private int protectionBufferSize

useProtectedDC

private boolean useProtectedDC

hasPbsz

private boolean hasPbsz
Constructor Detail

FTPConnection.ConnectionState

FTPConnection.ConnectionState(java.net.Socket plaintext)
Initialises the state using a plain text socket.

Parameters:
plaintext -
Method Detail

init

public void init()
          throws java.io.IOException
Initialises the internal state. All streams are plain text so far, until upgraded to secure.

Throws:
java.io.IOException - - when there's an error with the sockets.

isCCSecure

public boolean isCCSecure()
Returns whether the current control connection is secured.

Returns:
true if the the current control connection is secured.

isCCPlainText

public boolean isCCPlainText()
Returns true if the control connection is plain text

Returns:
true if the control connection is plain text

getCCOutputBuffer

public CRLFPrintWriter getCCOutputBuffer()
Returns the output buffer for the control connection

Returns:
the output buffer for the control connection

getCCInputBuffer

public java.io.BufferedReader getCCInputBuffer()
Returns the input buffer for the control connection

Returns:
the input buffer for the control connection

upgradeCCToSSL

public boolean upgradeCCToSSL()
Upgrades the control connection to use SSL.

Returns:
true if control connection just got encrypted.

downgradeCCtoPlainText

public void downgradeCCtoPlainText()
Closes the SSL layer on top of the command channel but keeps the CC channel in clear mode. Only happens if the CC channel is in secure mode, otherwise it is left the way it is.


closeSockets

public void closeSockets()
                  throws java.io.IOException
Closes the sockets streams and then the sockets.

Throws:
java.io.IOException - - if something goes bad.

getCurrentSocket

public java.net.Socket getCurrentSocket()
Gets the current active socket (either SSL or not)

Returns:
the current active socket

sendReply

public void sendReply(java.lang.String message)
Sends a reply to the client, using the current output stream (either SSL or not)

Parameters:
message -

setProtectionBuffer

public void setProtectionBuffer(int size)
Sets the protection buffer to the given size. But size is usually 0 because TLS does no data channel encapsulation.

Parameters:
size - = new size for protection buffer.

hasIssuedPBSZ

public boolean hasIssuedPBSZ()
Check if a protection buffer size has been set to something 0 or greater;

Returns:
if PBSZ command executed successfully

setProtectionLevel

public void setProtectionLevel(java.lang.String level)
Sets the protection level of the communication channel.

Parameters:
level - - "P" for protection or "C" for clear.

getClientSocket

public java.net.Socket getClientSocket()
Returns a data connection socket, SSL if needed.

Returns:
a SSL socket if PROT P was issued, else a normal socket.

getDataOutputStream

public java.io.OutputStream getDataOutputStream()
                                         throws java.io.IOException
Gets the data output stream, either SSL or not.

Returns:
- data output stream.
Throws:
java.io.IOException

getDataInputStream

public java.io.InputStream getDataInputStream()
                                       throws java.io.IOException
Gets the data input stream, either SSL or not.

Returns:
- data input stream.
Throws:
java.io.IOException