com.glub.secureftp.bean
Class FTPCommand

java.lang.Object
  extended by com.glub.secureftp.bean.FTPCommand
Direct Known Subclasses:
SSLFTPCommand

public class FTPCommand
extends Object

The FTPCommand class is responsible for handling the standard commands used in the File Transfer Protocol.

Since:
2.5.5
Version:
$Revision: 47 $, $Date: 2009-12-01 23:35:56 -0800 (Tue, 01 Dec 2009) $

Constructor Summary
FTPCommand(BufferedReader reader, PrintWriter writer)
          Create a new FTPCommand object.
FTPCommand(BufferedReader reader, PrintWriter writer, OutputStream sendCmdStream, OutputStream recvCmdStream)
          Create a new FTPCommand object.
 
Method Summary
 void abort(FTPData data)
          Abort a data transfer.
 void acct(String account)
          Specify the account name to the FTP server.
 void append(String file, FTPData data)
          Append to a file on the FTP server.
 void cdup()
          Move up one directory on the FTP server.
 void chdir(String dir)
          Change remote directory on the FTP server.
 void delete(String filename)
          Delete a file from the FTP server.
 void forcePasvToUseControlIP(boolean on)
          Forces passive data transfers to use the control socket IP address.
 String getReply()
          Get the last full reply from the FTP server.
 int getReplyCode()
          Get the last reply code from the FTP server.
 String getReplyMessage()
          Get the last reply message from the FTP server.
 String help(String item)
          Get help from the FTP server.
 void list(String itemsToList, FTPData data, boolean showHidden)
          List files in a directory on the FTP server.
 Date mdtm(String file)
          Get the modification time of a file on the FTP server.
 void mkdir(String dir)
          Make a directory on the FTP server.
 void modeZ()
          Mode Z compression
 void nlst(String itemsToList, FTPData data)
          NList files in a directory on the FTP server.
 void noop()
          Send a noop to the FTP server.
 void pass(String password)
          Specify the password for logging in to the FTP server.
 HostInfo pasv()
          Request a PASV data transfer from the FTP server.
 void port(HostInfo hostInfo)
          Request a PORT data transfer from the FTP server.
 String pwd()
          Get the working directory on the FTP server.
 void quit()
          Quit the FTP session.
 void raw(String rawCmd)
          Send a raw command to the FTP server.
protected  void recvCmd()
          Receive the message back from the FTP server.
 void rename(String from, String to)
          Rename a file on the FTP server.
 void rest(long byteOffset)
          Restart an incomplete file transfer.
 void retrieve(String file, FTPData data)
          Retrieve a file from the FTP server.
 void rmdir(String dir)
          Remove a directory from the FTP server.
protected  void sendCmd(String cmd)
          Send a command to the FTP server.
protected  void sendCmd(String cmd, String cmdMask)
          Send a command to the FTP server with command masking for client reporting.
 void setControlIP(String ip)
          Sets the control channel IP address.
 void setRecvCmdStream(OutputStream recvCmdStream)
          Set the stream responsible for getting replies from the FTP server.
 void setSendCmdStream(OutputStream sendCmdStream)
          Set the stream responsible for getting commands sent to the FTP server.
 long size(String filename)
          Get the size of a file from the FTP server.
 void store(String file, FTPData data)
          Store a file on the FTP server.
 String syst()
          Get system information from the FTP server.
 void type(char t)
          Set the type of transfer.
 void user(String username)
          Specify the username for logging in to the FTP server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FTPCommand

public FTPCommand(BufferedReader reader,
                  PrintWriter writer)
Create a new FTPCommand object.

Parameters:
reader - based on the input stream from the control socket.
writer - based on the output stream from the control socket.

FTPCommand

public FTPCommand(BufferedReader reader,
                  PrintWriter writer,
                  OutputStream sendCmdStream,
                  OutputStream recvCmdStream)
Create a new FTPCommand object.

Parameters:
reader - based on the input stream from the control socket.
writer - based on the output stream from the control socket.
sendCmdStream - stream used to report commands set to the FTP server.
recvCmdStream - stream used to report commands received from the FTP server.
Method Detail

setRecvCmdStream

public void setRecvCmdStream(OutputStream recvCmdStream)
Set the stream responsible for getting replies from the FTP server.

Parameters:
recvCmdStream - the stream used to get replies from the FTP server.

setSendCmdStream

public void setSendCmdStream(OutputStream sendCmdStream)
Set the stream responsible for getting commands sent to the FTP server.

Parameters:
sendCmdStream - the stream used to get the commands sent to the FTP server.

user

public void user(String username)
          throws FTPNeedPasswordException,
                 FTPNeedAccountException,
                 FTPBadLoginException,
                 FTPException,
                 IllegalArgumentException
Specify the username for logging in to the FTP server.

Parameters:
username - name of the user attempting to login.
Throws:
FTPNeedPasswordException - if a password is required for login.
FTPNeedAccountException - if account name is required for login.
FTPBadLoginException - if login is denied.
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if username is missing.

pass

public void pass(String password)
          throws FTPNeedAccountException,
                 FTPBadLoginException,
                 FTPException,
                 IllegalArgumentException
Specify the password for logging in to the FTP server.

Parameters:
password - password for the user attempting to login
Throws:
FTPNeedAccountException - if account name is required for login.
FTPBadLoginException - if login is denied.
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if username is missing.

acct

public void acct(String account)
          throws FTPBadLoginException,
                 FTPException,
                 IllegalArgumentException
Specify the account name to the FTP server.

Parameters:
account - account name for the user attempting to login
Throws:
FTPBadLoginException - if login is denied.
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if username is missing.

quit

public void quit()
          throws FTPException
Quit the FTP session.

Throws:
FTPException - if the FTP server returns an error code.

syst

public String syst()
            throws FTPException
Get system information from the FTP server.

Returns:
system information as returned by the remote server.
Throws:
FTPException - if the FTP server returns an error code.

delete

public void delete(String filename)
            throws FTPException,
                   IllegalArgumentException
Delete a file from the FTP server.

Parameters:
filename - name of the file to delete.
Throws:
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if filename is missing.

rename

public void rename(String from,
                   String to)
            throws FTPException,
                   IllegalArgumentException
Rename a file on the FTP server.

Parameters:
from - existing name of the file.
to - new name for the file.
Throws:
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if either from or to is missing.

mkdir

public void mkdir(String dir)
           throws FTPException,
                  FTPAccessDeniedException,
                  IllegalArgumentException
Make a directory on the FTP server.

Parameters:
dir - new directory name.
Throws:
FTPAccessDeniedException - if the directory couldn't be created due to access restrictions.
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if dir is missing.

rmdir

public void rmdir(String dir)
           throws FTPException,
                  IllegalArgumentException
Remove a directory from the FTP server.

Parameters:
dir - new directory name.
Throws:
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if dir is missing.

rest

public void rest(long byteOffset)
          throws FTPException
Restart an incomplete file transfer.

Parameters:
byteOffset - the amount of bytes to seek into the restore.
Throws:
FTPException - if the FTP server returns an error code.

mdtm

public Date mdtm(String file)
          throws FTPNoSuchFileException,
                 FTPException,
                 IllegalArgumentException
Get the modification time of a file on the FTP server.

Parameters:
file - the name of the file.
Returns:
the file time or null if the time could not be determined.
Throws:
FTPNoSuchFileException - if filename does not exist.
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if file is missing.

chdir

public void chdir(String dir)
           throws FTPNotADirectoryException,
                  FTPNoSuchFileException,
                  FTPException,
                  IllegalArgumentException
Change remote directory on the FTP server.

Parameters:
dir - the directory name.
Throws:
FTPNotADirectoryException - if dir is not a directory.
FTPNoSuchFileException - if dir does not exist.
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if dir is missing.

cdup

public void cdup()
          throws FTPException
Move up one directory on the FTP server.

Throws:
FTPException - if the FTP server returns an error code.

pwd

public String pwd()
           throws FTPException
Get the working directory on the FTP server.

Returns:
the working directory on the FTP server, or null if the results could not be parsed.
Throws:
FTPException - if the FTP server returns an error code.

abort

public void abort(FTPData data)
           throws FTPException,
                  IllegalArgumentException
Abort a data transfer.

This method is not synchronized since abort may need to interrupt another method executing on the same object.

Parameters:
data - an Object that implements the FTPData interface.
Throws:
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if data is missing.

retrieve

public void retrieve(String file,
                     FTPData data)
              throws FTPException,
                     IOException,
                     IllegalArgumentException
Retrieve a file from the FTP server.

Parameters:
file - name of the file.
data - an Object that implements the FTPData interface.
Throws:
FTPException - if the FTP server returns an error code.
IOException - if there are socket problems.
IllegalArgumentException - if either file or data is missing.

store

public void store(String file,
                  FTPData data)
           throws FTPException,
                  IOException,
                  IllegalArgumentException
Store a file on the FTP server.

Parameters:
file - name of the file.
data - an Object that implements the FTPData interface.
Throws:
FTPException - if the FTP server returns an error code.
IOException - if there are socket problems.
IllegalArgumentException - if either file or data is missing.

append

public void append(String file,
                   FTPData data)
            throws FTPException,
                   IOException,
                   IllegalArgumentException
Append to a file on the FTP server.

Parameters:
file - name of the file.
data - an Object that implements the FTPData interface.
Throws:
FTPException - if the FTP server returns an error code.
IOException - if there are socket problems.
IllegalArgumentException - if either file or data is missing.

type

public void type(char t)
          throws FTPException
Set the type of transfer.

Parameters:
t - the transfer type ('A' = ascii, 'I' = binary image).
Throws:
FTPException - if the FTP server returns an error code.

modeZ

public void modeZ()
           throws FTPException
Mode Z compression

Throws:
FTPException - if the FTP server returns an error code.

size

public long size(String filename)
          throws FTPNoSuchFileException,
                 FTPException,
                 IllegalArgumentException
Get the size of a file from the FTP server.

Parameters:
filename - name of the file.
Returns:
size of the file, or -1 if the results could not be parsed.
Throws:
FTPNoSuchFileException - if filename does not exist.
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if filename is missing.

list

public void list(String itemsToList,
                 FTPData data,
                 boolean showHidden)
          throws FTPException,
                 IOException,
                 IllegalArgumentException
List files in a directory on the FTP server.

Parameters:
itemsToList - the items to list.
data - an Object that implements the FTPData interface.
showHidden - flag to show hidden files (subject to availibility)
Throws:
FTPException - if the FTP server returns an error code.
IOException - if there are socket problems.
IllegalArgumentException - if data is missing.

nlst

public void nlst(String itemsToList,
                 FTPData data)
          throws FTPException,
                 IOException,
                 IllegalArgumentException
NList files in a directory on the FTP server.

Parameters:
itemsToList - the items to list.
data - an Object that implements the FTPData interface.
Throws:
FTPException - if the FTP server returns an error code.
IOException - if there are socket problems.
IllegalArgumentException - if data is missing.

port

public void port(HostInfo hostInfo)
          throws FTPException,
                 IllegalArgumentException
Request a PORT data transfer from the FTP server.

Parameters:
hostInfo - HostInfo for the local listening socket.
Throws:
FTPException - if the FTP server returns an error code.
IllegalArgumentException - if hostInfo is null

pasv

public HostInfo pasv()
              throws FTPException
Request a PASV data transfer from the FTP server.

Returns:
HostInfo for connecting to the remote data socket, or null if the results could not be parsed.
Throws:
FTPException - if the FTP server returns an error code.

help

public String help(String item)
            throws FTPException
Get help from the FTP server.

Parameters:
item - item to get help on from server
Throws:
FTPException - if the FTP server returns an error code.

raw

public void raw(String rawCmd)
         throws FTPException
Send a raw command to the FTP server.

Parameters:
rawCmd - command to send to the server
Throws:
FTPException - if the FTP server returns an error code.

noop

public void noop()
          throws FTPException
Send a noop to the FTP server.

Throws:
FTPException - if the FTP server returns an error code.

getReply

public String getReply()
Get the last full reply from the FTP server.

Returns:
the last reply from the FTP server.

getReplyCode

public int getReplyCode()
Get the last reply code from the FTP server.

Returns:
the last reply code from the FTP server.

getReplyMessage

public String getReplyMessage()
Get the last reply message from the FTP server.

Returns:
the last reply message from the FTP server.

sendCmd

protected void sendCmd(String cmd)
                throws FTPException
Send a command to the FTP server.

Parameters:
cmd - the command to send to the FTP server.
Throws:
FTPException - if the FTP server returns an error code.

sendCmd

protected void sendCmd(String cmd,
                       String cmdMask)
                throws FTPException
Send a command to the FTP server with command masking for client reporting. This is useful for PASS and ACCT so nobody sees what actually was sent.

Parameters:
cmd - the command to send to the FTP server.
cmdMask - the command mask that will be returned to the client.
Throws:
FTPException - if the FTP server returns an error code.

recvCmd

protected void recvCmd()
                throws FTPException
Receive the message back from the FTP server.

Throws:
FTPException - if the FTP server returns an error code.

forcePasvToUseControlIP

public void forcePasvToUseControlIP(boolean on)
Forces passive data transfers to use the control socket IP address.

Parameters:
on - true if to use control socket IP, false if off.

setControlIP

public void setControlIP(String ip)
Sets the control channel IP address.

Parameters:
ip - the control socket IP
See Also:
forcePasvToUseControlIP(boolean)


Copyright © 2000-08 Glub Tech, Inc. All Rights Reserved.