ip1.ex14
Class JFtpControl

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--ip1.ex14.JFtpThread
              |
              +--ip1.ex14.JFtpControl
All Implemented Interfaces:
java.lang.Runnable

public class JFtpControl
extends JFtpThread

The JFtpControl class implements an FTP control thread. Depending on the chosen threading model, at any moment there can be zero, one or any number of control threads running simultaneously. All control threads are owned by the JFtp instance. A control thread may own JFtpData threads.

Version:
$Id: JFtpControl.java,v 1.42 2003/10/17 14:03:39 sharky Exp $
See Also:
JFtp, JFtpData, JFtpResponse

Nested Class Summary
(package private)  class JFtpControl.ControlQueueItem
          Class for describing a JFtpControl's queue.
(package private)  class JFtpControl.IdleTask
          A TimerTask to watch inactivity on a JFtpControlThread.
 
Nested classes inherited from class ip1.ex14.JFtpThread
 
Field Summary
private  java.io.BufferedReader in
           
protected  java.io.File localDir
          The local working directory.
private  java.io.PrintWriter out
           
protected  boolean passive
          Are we in passive mode?
protected  java.net.URL remoteUrl
          The remote working URL.
protected  java.net.Socket sockControl
          Control connection.
static int STATE_CONNECT
          We are connected .
static int STATE_LOGGED
          We have logged in.
 
Fields inherited from class ip1.ex14.JFtpThread
children, counter, id, node, parent, queue, state, STATE_EXITED, STATE_NOTRUNNING, STATE_SHUTDOWN, threadTree, threadTreeChanged, type
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
JFtpControl(JFtp jftp, java.net.URL url)
          The constructor.
 
Method Summary
(package private)  void die_command(java.lang.String cmd)
          The command issued is not allowed in current state.
private  void makeCwd(JFtpEntry entry)
          Change the remote working directory.
private  void makeDele(JFtpEntry entry)
          Delete a remote file.
private  JFtpResponse makeList()
          Returns the directory listing.
private  JFtpResponse makeNoop()
          Send a NOOP command.
private  JFtpResponse makePass()
          Sent the user's password.
private  JFtpResponse makePwd()
          Prints current working directory.
private  void makeQuit()
          Says goodbye to the FTP server.
private  void makeRetr(JFtpEntry entry)
          Retrieve a remote file.
private  void makeStor(JFtpEntry entry)
          Send a file to the server.
private  boolean makeType(java.lang.String type)
          Set the transfer type.
private  JFtpResponse makeUser()
          Authenticate.
 void queueCwd(JFtpEntry entry)
          Queue a CWD command.
 void queueDele(JFtpEntry entry)
          Queue a DELE command.
 void queueList()
          Queue a LIST command.
 void queueNoop()
          Queue a NOOP command.
 void queuePwd()
          Queue a PWD command.
 void queueRetr(JFtpEntry entry)
          Queue a RETR command.
 void queueStor(JFtpEntry entry)
          Queue a STOR command.
protected  JFtpResponse recvResponse()
          Receive and process a reponse from the server.
 void run()
          The thread's entry point.
protected  void sendCommand(java.lang.String strng)
          Sends a string to the remote host.
protected  void shutdown()
          Close reader, writer and socket.
 
Methods inherited from class ip1.ex14.JFtpThread
addChild, addQueue, debug, dumpQueue, getChild, getRoot, isBusy, peekQueue, propagateTreeChange, queueShutdown, readQueue, refreshNode, refreshThreadView, removeChild, reset, toString, waitShutdown
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sockControl

protected java.net.Socket sockControl
Control connection.


STATE_CONNECT

public static final int STATE_CONNECT
We are connected .

See Also:
Constant Field Values

STATE_LOGGED

public static final int STATE_LOGGED
We have logged in.

See Also:
Constant Field Values

localDir

protected java.io.File localDir
The local working directory.


remoteUrl

protected java.net.URL remoteUrl
The remote working URL.


passive

protected boolean passive
Are we in passive mode?


in

private java.io.BufferedReader in

out

private java.io.PrintWriter out
Constructor Detail

JFtpControl

public JFtpControl(JFtp jftp,
                   java.net.URL url)
The constructor.

Parameters:
jftp - the JFtp paren thread
url - the starting URL
Method Detail

die_command

void die_command(java.lang.String cmd)
The command issued is not allowed in current state.

Parameters:
cmd - the rejected command

run

public void run()
The thread's entry point.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class JFtpThread

recvResponse

protected JFtpResponse recvResponse()
Receive and process a reponse from the server.

See Also:
sendCommand(java.lang.String), JFtpResponse

sendCommand

protected void sendCommand(java.lang.String strng)
Sends a string to the remote host.

Parameters:
strng - the string to send
See Also:
recvResponse()

shutdown

protected void shutdown()
Close reader, writer and socket.

Overrides:
shutdown in class JFtpThread

makeCwd

private void makeCwd(JFtpEntry entry)
Change the remote working directory.

See Also:
queueCwd(ip1.ex14.JFtpEntry)

makeDele

private void makeDele(JFtpEntry entry)
Delete a remote file.

See Also:
queueDele(ip1.ex14.JFtpEntry)

makeList

private JFtpResponse makeList()
Returns the directory listing.

See Also:
queueList(), JFtpData.queueReadStr(java.lang.StringBuffer), JFtp.dispRemote(java.util.Vector)

makeNoop

private JFtpResponse makeNoop()
Send a NOOP command.

See Also:
queueNoop(), JFtpControl.IdleTask

makePass

private JFtpResponse makePass()
Sent the user's password.


makePwd

private JFtpResponse makePwd()
Prints current working directory.

See Also:
queuePwd()

makeRetr

private void makeRetr(JFtpEntry entry)
Retrieve a remote file.

Parameters:
entry - the file we are retrieving
See Also:
makeType(java.lang.String), queueRetr(ip1.ex14.JFtpEntry), recvResponse(), sendCommand(java.lang.String), JFtpData.queueReceive(java.io.File)

makeStor

private void makeStor(JFtpEntry entry)
Send a file to the server.

See Also:
makeType(java.lang.String), queueStor(ip1.ex14.JFtpEntry), recvResponse(), sendCommand(java.lang.String), JFtpData.queueSend(java.io.File)

makeType

private boolean makeType(java.lang.String type)
Set the transfer type.

Parameters:
type - the transfer type
See Also:
makeRetr(ip1.ex14.JFtpEntry), makeStor(ip1.ex14.JFtpEntry), sendCommand(java.lang.String), recvResponse()

makeQuit

private void makeQuit()
Says goodbye to the FTP server.

See Also:
sendCommand(java.lang.String), recvResponse()

makeUser

private JFtpResponse makeUser()
Authenticate.

See Also:
makePass()

queueCwd

public void queueCwd(JFtpEntry entry)
Queue a CWD command.

See Also:
makeCwd(ip1.ex14.JFtpEntry)

queueDele

public void queueDele(JFtpEntry entry)
Queue a DELE command.

See Also:
makeDele(ip1.ex14.JFtpEntry), JFtpWindow.actionPerformed(java.awt.event.ActionEvent)

queueList

public void queueList()
Queue a LIST command.

See Also:
makeList()

queueNoop

public void queueNoop()
Queue a NOOP command.

See Also:
makeNoop()

queuePwd

public void queuePwd()
Queue a PWD command.

See Also:
makePwd()

queueRetr

public void queueRetr(JFtpEntry entry)
Queue a RETR command.

See Also:
makeRetr(ip1.ex14.JFtpEntry)

queueStor

public void queueStor(JFtpEntry entry)
Queue a STOR command.

See Also:
makeStor(ip1.ex14.JFtpEntry)