Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.finj
Class FTPClient  view FTPClient download FTPClient.java

java.lang.Object
  extended byorg.finj.FTPClient

public class FTPClient
extends java.lang.Object

FIXME : mention default values.

Version:
$Id$

Field Summary
static int ASCII_DATA_TYPE
          Default transfer type, intended primarily for the transfer of text files except when both hosts would find EBCDIC more convenient.
static int BLOCK_DATA_TRANSMISSION_MODE
          The file is transmitted as a series of data blocks preceded by one or more header bytes.
static int COMPRESSED_DATA_TRANSMISSION_MODE
          There are three kinds of information to be sent : regular data, sent in a byte string; compressed data, consisting of replications or filler; and control information, sent in a two-byte escape sequence.
private  boolean connected
           
private  int control_port
           
private  java.io.BufferedReader ctrlIn
           
private  java.io.PrintWriter ctrlOut
           
private  byte[] dataHost
           
private  java.io.InputStream dataIn
           
private  int dataMode
           
private  java.io.OutputStream dataOut
           
private  byte[] dataPort
           
private  int dataStructure
           
private  int dataType
           
private  int dataTypeLength
           
static int DEFAULT_FTP_PORT
          Default FTP port value is '21'.
static java.util.Locale DEFAULT_LOCALE
          Default Locale used when none is provided at construction time.
private static int DOWNLOAD_TRANSFER
          constant used to differentiate between upload traffic and download traffic
static int EBCDIC_DATA_TYPE
          Intended for efficient transfer between hosts which use EBCDIC for their internal character representation.
static int FILE_DATA_STRUCTURE
          Default structure assumed if the setTransferStructure has not been used.
static int IMAGE_DATA_TYPE
          Data are sent as contiguous bits which, for transfer, are packed into the 8-bit transfer bytes.
static int LOCAL_DATA_TYPE
          Data is transferred in logical bytes of the size specified by the obligatory sceond parameter, Byte size.
private  java.util.Locale locale
           
private  java.net.InetAddress localhost
           
private  FTPClientObserver observer
           
static int PAGE_DATA_STRUCTURE
          To transmit files that are discontinuous, FTP defines a page structure.
static int RECORD_DATA_STRUCTURE
          Record structures must be accepted for "text" files (i.e., files with ASCII or EBCDIC types) by all FTP implementations.
private  java.net.InetAddress serverhost
           
static int STREAM_DATA_TRANSMISSION_MODE
          The data is transmitted as a stream of bytes.
private static int UPLOAD_TRANSFER
          constant used to differentiate between upload traffic and download traffic
 
Constructor Summary
FTPClient()
          Constructs a new instance of this class.
FTPClient(java.util.Locale locale)
          Constructs a new instance of this class using the provided Locale for internationalization of FTPReplys...
FTPClient(java.lang.String server)
          Constructs a new instance of this class that will try to connect to the server through the DEFAULT_FTP_PORT.
FTPClient(java.lang.String server, int port)
          Constructs a new instance of this class that will try to connect to the server througn the provided port.
FTPClient(java.lang.String server, int port, java.util.Locale locale)
          Constructs a new instance of this class that will try to connect to the server througn the provided port.
FTPClient(java.lang.String server, int port, java.lang.String user, java.lang.String pass)
          Constructs a new instance of this class that will try to connect to the server through the provided port, and try to log in using user and pass login information.
FTPClient(java.lang.String server, int port, java.lang.String user, java.lang.String pass, java.util.Locale locale)
          Constructs a new instance of this class that will try to connect to the server through the provided port, and try to log in using user and pass login information.
FTPClient(java.lang.String server, java.util.Locale locale)
          Constructs a new instance of this class that will try to connect to the server through the DEFAULT_FTP_PORT.
FTPClient(java.lang.String server, java.lang.String user, java.lang.String pass)
          Constructs a new instance of this class that will try to connect to the server through the DEFAULT_FTP_PORT, and try to log in using user and pass login information.
FTPClient(java.lang.String server, java.lang.String user, java.lang.String pass, java.util.Locale locale)
          Constructs a new instance of this class that will try to connect to the server through the DEFAULT_FTP_PORT, and try to log in using user and pass login information.
 
Method Summary
 void abortCommand()
          This command tells the server to abort the previous FTP service command and any associated transfer of data.
 void allocateSpace(int bytes)
          This command may be required by some servers to reserve sufficient storage to accomodate the new file to be transferred.
 void allocateSpace(int space, int size)
          This command works just as allocateSpace (int), except that it allows to set a second (optional) parameter that may be required for files sent with record or page structure : a maximum record or page size.
 void appendToFile(java.io.InputStream data, java.lang.String pathname)
          This command causes the server-DTP to accept the data transferred and to store the data in a file at the server site.
 void ascii()
          Deprecated. use FTPClient.setDataType (FTPClient.ASCII_DATA_TYPE) instead. THIS METHOD WILL NOT BE CONTINUED.
 void binary()
          Deprecated. use FTPClient.setDataType (FTPClient.IMAGE_DATA_TYPE) instead. THIS METHOD WILL NOT BE CONTINUED.
protected  void broadcastCommand(java.lang.String command)
          Broadcasts the command sent to the server to the current observer, if any.
protected  void broadcastReply(FTPReply reply)
          Broadcasts the reply received from the server to the current observer, if any.
 void cd(java.lang.String pathname)
          Deprecated. use FTPClient.setWorkingDirectory (String) instead. THIS METHOD WILL NOT BE CONTINUED.
 boolean checkConnection()
          This command does not affect any parameters or previously entered commands.
 void close()
          This method terminates a user and if file transfer is not in progress, the server closes the control connection.
 void closeServer()
          Deprecated. use FTPClient.close () instead. THIS METHOD WILL NOT BE CONTINUED.
protected  void dataReceived(int bytes)
          Broadcasts the amount of data received from the server to the observer, if any.
protected  void dataSent(int bytes)
          Broadcasts the amount of data received from the server to the observer, if any.
 void deleteFile(java.lang.String pathname)
          This command causes the file specified as the pathname parameter to be deleted at the server site.
private  int doPASSCommand(java.lang.String pass)
          Utility routine that takes care to send password information to the server and treat it's answer.
private  void doRNFRCommand(java.lang.String from)
          Utility routine that takes care to send current name information to the server and treat it's answer in order to rename it.
private  void doRNTOCommand(java.lang.String to)
          Utility routine that takes care to send new name information to the server and treat it's answer in order to rename a file.
 java.lang.String doSite(java.lang.String command)
          This command is used by the server to provide services specific to his system that are essential to file transfer but not sufficiently universal to be included as commands in the protocol.
private  int doUSERCommand(java.lang.String user)
          Utility routine that takes care to send user information to the server and treat it's answer.
private  void downloadData(java.io.InputStream in, java.io.OutputStream out)
          Transfers all data coming from server to the local host in a format that corresponds to the one set with setDataType(int).
 sun.net.TelnetInputStream get(java.lang.String pathname)
          Deprecated. use FTPClient.getFile (String) instead. THIS METHOD WILL NOT BE CONTINUED.
private  java.io.InputStream getDataInputStream(java.net.ServerSocket localSocket)
          Performs the second half of data connection establishment : a Socket is ready on local host, the server is knocking at that door.
private  java.io.OutputStream getDataOutputStream(java.net.ServerSocket localSocket)
          Performs the second half of data connection establishment : a Socket is ready on local host, the server is knocking at that door.
 byte[] getDataPort()
          Returns the HOST-PORT used for the data connection.
 int getDataStructure()
          Returns the current data structure manipulated, that is one of FTPClient.FILE_DATA_STRUCTURE (default value), FTPClient.RECORD_DATA_STRUCTURE, FTPClient.PAGE_DATA_STRUCTURE.
 int getDataTransferMode()
          Returns the data transmission mode currently used, that is one of FTPClient.STREAM_DATA_TRANSMISSION_MODE (default value), FTPClient.BLOCK_DATA_TRANSMISSION_MODE, FTPClient.COMPRESSED_DATA_TRANSMISSION_MODE.
 int getDataType()
          Returns the current data type manipulated, that is one of FTPClient.ASCII_DATA_TYPE (default value), FTPClient.EBCDIC_DATA_TYPE, FTPClient.IMAGE_DATA_TYPE, FTPClient.LOCAL_DATA_TYPE.
 void getFile(java.io.OutputStream destination, java.lang.String pathname)
          This command causes the server-DTP to transfer a copy of the file, specified in the pathname, to this client.
 RemoteFile[] getFileDescriptors()
          Returns the complete description of the files in the current working directory.
 RemoteFile[] getFileDescriptors(java.lang.String pathname)
          Returns the complete description of the files in the directory specified by the path argument.
 void getFileFrom(java.io.OutputStream destination, java.lang.String pathname, int position)
          The position argument field represents the server marker at which file transfer is to be restarted.
 java.lang.String[] getFileNames()
          Returns a directory listing for the current working directory.
 java.lang.String[] getFileNames(java.lang.String pathname)
          Returns a directory listing for the path provided as parameter.
 FTPClientObserver getObserver()
          Returns the current observer of this instance.
 java.lang.String getServerStatus()
          Returns the status response from the server.
 java.lang.String getServerStatus(java.lang.String pathname)
          Returns the status response from the server.
 java.lang.String getServerSystemName()
          Returns the type of operating system at the server, one of the system names listed in the current version of the 'Assigned Numbers Document' (as of 31-jul-00 : RFC1700).
 java.lang.String getWorkingDirectory()
          This command causes the name of the current working directory to be returned.
 boolean hasObserver()
          Tells if this instance is currently being observed.
 boolean isConnected()
          Returns true if a control connection is currently opened between this client and a FTP server, false else.
protected  void isConnected(boolean isIt)
          Sets the current status of the control connection to the value provided as parameter.
 void login(java.lang.String user, java.lang.String pass)
          Log to the current server using the provided login information.
 void logout()
          This method terminates a user, flushing all I/O and account information, except to allow any transfer in progress to be completed.
 void makeDirectory(java.lang.String pathname)
          This command causes the directory specified in the pathname to be created as a directory (if the pathname is absolute) or as a subdirectory of the current working directory (if the pathname is relative).
 void mountStructure(java.lang.String system)
          This command allows the user to mount a different file system data structure without altering his login or accounting information.
protected  java.lang.String notValidReplyCodeMessage(int code, java.lang.String cmd)
          Utility routine that composes the message used for FTPExceptions.
 void open(java.lang.String server)
          Connects to the server through the DEFAULT_FTP_PORT.
 void open(java.lang.String server, int port)
          Connects to the server through the provided port.
 void openServer(java.lang.String server)
          Deprecated. use FTPClient.open (String) instead. THIS METHOD WILL NOT BE CONTINUED.
 void openServer(java.lang.String server, int port)
          Deprecated. use FTPClient.open (String, int) instead. THIS METHOD WILL NOT BE CONTINUED.
private  java.net.ServerSocket prepareDataConnection(int direction)
          Performs the first half of data connection establishment : Opens a new ServerSocket on the local host and tells the FTP Server on which port to connect.
private  java.net.ServerSocket prepareDataConnection(short usePort)
          Performs the first half of data connection establishment : Opens a new ServerSocket on the local host and tells the FTP Server on which port to connect.
 sun.net.TelnetOutputStream put(java.lang.String pathname)
          Deprecated. use FTPClient.putFile (InputStream, String) instead. THIS METHOD WILL NOT BE CONTINUED.
 void putFile(java.io.InputStream data, java.lang.String pathname)
          This command causes the server-DTP to accept the data transferred and to store the data as a file at the server site.
 java.lang.String putUniqueFile(java.io.InputStream data)
          This command behaves like putFile (InputStream, String) except that the resultant file is to be created in the current directory nder a name unique to that directory.
protected  FTPReply readFTPReply()
          Reads replies sent by FTP server on the control stream and notifies the observer (if it exists).
protected  java.lang.String readLineFromControlConnection()
          Reads a line from the control connection and returns it without any change.
protected  java.lang.String readMultilineReply(FTPReply reply)
          Utility routine used by mutli-line commands to read the whole stuff from the control connection.
 void removeDirectory(java.lang.String pathname)
          This command causes the directory specified in the pathname to be removed as a directory (if the pathname is absolute) or as a subdirectory of the current working directory (if the pathname is relative).
 void removeObserver()
          Removes the current observer of this instance, if any.
 void renameFile(java.lang.String from, java.lang.String to)
          This command causes a file to be renamed from its old pathname to its new pathname.
protected  void sendFTPCommand(java.lang.String command)
          Writes the command to the control stream and nofifies the observer (if it exists).
 void setAccount(java.lang.String value)
          The account data is used to indentify user's account, but is not necessarily related to the username used to log in, as some sites may require an account for login and others only for specific access, such as storing files.
 void setDataPort(byte host_1, byte host_2, byte host_3, byte host_4, byte port_1, byte port_2)
          Defines the HOST-PORT specification for the data port to be used in data connection.
 void setDataPort(int host, short port)
          Defines the HOST-PORT specification for the data port to be used in data connection.
 void setDataPort(short port)
          Defines the HOST-PORT specification for the data port to be used in data connection.
 void setDataStructure(int structure)
          In addition to different representation types, FTP allows the structure of a file to be specified.
 void setDataTransferMode(int mode)
          There are three transmission mode available, one which formats the data and allows for restart procedures; one which also compresses the data for efficient transfer; and one which passes the data with little or no processing.
 void setDataType(int type)
          Data representations are handled in FTP by a user specifying a representation type.
 void setDataType(int type, int bytes)
          Works just as setDataType (int), except that if the type is FTPClient.LOCAL_DATA_TYPE, then the second parameter (which is useless for the other types) must be the "logical byte size".
 void setObserver(FTPClientObserver observer)
          Sets the observer of this object to be the one passed as parameter.
 byte[] setPassive()
          This command requests the server-DTP to "listen" on a data port (which is not its default data port) and to wait for a connection rather that initiate one upon receipt of a transfer command.
 void setWorkingDirectory(java.lang.String pathname)
          This command allows the user to work with a different directory or dataset for file storage or retrieval without altering his login of accounting information.
 void setWorkingDirectoryUp()
          This command is a special case of setWorkingDirectory (String), and is included to simplify the implementation of programs for transferring directory trees between operating systems having different syntaxes for naming the parent directory.
protected  byte[] toByteArray(int value)
          Utility routine that takes an int value and chops it into a 4 bytes array.
protected  byte[] toByteArray(short value)
          Utility routine that takes a short value and chops it into a 2 bytes array.
protected  int toInt(byte[] value)
          Utility routine that takes a byte array value and links it into an int value.
protected  short toUnsignedShort(byte value)
          Utility routine that takes a byte value and transcripts it into a short value.
private  void transferASCIIData(java.io.InputStream in, java.io.OutputStream out, int direction)
          Transfers all data coming from in to out in ASCII format.
private  void transferData(java.io.InputStream in, java.io.OutputStream out)
          Transfers all data coming from in to out in a format that corresponds to the one set with setDataType(int).
private  void transferEBCDICData(java.io.InputStream in, java.io.OutputStream out, int direction)
          Transfers all data coming from in to out in EBCDIC format.
private  void transferImageData(java.io.InputStream in, java.io.OutputStream out, int direction)
          Transfers all data coming from in to out in Image format.
private  void transferLocalData(java.io.InputStream in, java.io.OutputStream out, int direction)
          Transfers all data coming from in to out in Local format.
private  void uploadData(java.io.InputStream in, java.io.OutputStream out)
          Transfers all data going from local host to the server in a format that corresponds to the one set with setDataType(int).
protected  void writeLineToControlConnection(java.lang.String line)
          Writes a line to the control connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOCALE

public static final java.util.Locale DEFAULT_LOCALE
Default Locale used when none is provided at construction time.

Since:
v1.0

DEFAULT_FTP_PORT

public static final int DEFAULT_FTP_PORT
Default FTP port value is '21'.

Since:
v1.0
See Also:
"RFC959-??", Constant Field Values

ASCII_DATA_TYPE

public static final int ASCII_DATA_TYPE
Default transfer type, intended primarily for the transfer of text files except when both hosts would find EBCDIC more convenient.

Since:
v1.0
See Also:
"RFC959-3:1:1:1", Constant Field Values

EBCDIC_DATA_TYPE

public static final int EBCDIC_DATA_TYPE
Intended for efficient transfer between hosts which use EBCDIC for their internal character representation.

Since:
v1.0
See Also:
"RFC959-3:1:1:2", Constant Field Values

IMAGE_DATA_TYPE

public static final int IMAGE_DATA_TYPE
Data are sent as contiguous bits which, for transfer, are packed into the 8-bit transfer bytes. [API DISCUSSION : wouldn't you prefer 'BINARY_DATA_TYPE']

Since:
v1.0
See Also:
"RFC959-3:1:1:3", Constant Field Values

LOCAL_DATA_TYPE

public static final int LOCAL_DATA_TYPE
Data is transferred in logical bytes of the size specified by the obligatory sceond parameter, Byte size.

Since:
v1.0
See Also:
"RFC959-3:1:1:4", Constant Field Values

FILE_DATA_STRUCTURE

public static final int FILE_DATA_STRUCTURE
Default structure assumed if the setTransferStructure has not been used. There is no internal structure and the file is considered to be a continuous sequence of data bytes.

Since:
v1.0
See Also:
"RFC959-3:1:2:1", Constant Field Values

RECORD_DATA_STRUCTURE

public static final int RECORD_DATA_STRUCTURE
Record structures must be accepted for "text" files (i.e., files with ASCII or EBCDIC types) by all FTP implementations.

Since:
v1.0
See Also:
"RFC959-3:1:2:2", Constant Field Values

PAGE_DATA_STRUCTURE

public static final int PAGE_DATA_STRUCTURE
To transmit files that are discontinuous, FTP defines a page structure. File of this type are sometimes known as "random access files" or even as "holey files". In these files there is sometimes other information associated with the file as a whole (e.g., a file descriptor), or with a section of the file (e.g., page access controls), or both. In FTP, the sections of the file are called pages. each page is sent with a page header.

Since:
v1.0
See Also:
"RFC959-3:1:2:3", Constant Field Values

STREAM_DATA_TRANSMISSION_MODE

public static final int STREAM_DATA_TRANSMISSION_MODE
The data is transmitted as a stream of bytes. There is no restriction on the representation type used; record structures are allowed.

Since:
v1.0
See Also:
"RFC959-3:4:1", Constant Field Values

BLOCK_DATA_TRANSMISSION_MODE

public static final int BLOCK_DATA_TRANSMISSION_MODE
The file is transmitted as a series of data blocks preceded by one or more header bytes. Record structures are allowed in this mode, and any representation type may be used.

Since:
v1.0
See Also:
"RFC959-3:4:2", Constant Field Values

COMPRESSED_DATA_TRANSMISSION_MODE

public static final int COMPRESSED_DATA_TRANSMISSION_MODE
There are three kinds of information to be sent : regular data, sent in a byte string; compressed data, consisting of replications or filler; and control information, sent in a two-byte escape sequence. Compressed mode is useful for obtaining increased bandwidth on very large netword transmissions at a litle extra CPU cost. It can be most effectively used to reduce the size of printer files such as those generated by RJE hosts.

Since:
v1.0
See Also:
"RFC959-3:4:3", Constant Field Values

UPLOAD_TRANSFER

private static final int UPLOAD_TRANSFER
constant used to differentiate between upload traffic and download traffic

See Also:
Constant Field Values

DOWNLOAD_TRANSFER

private static final int DOWNLOAD_TRANSFER
constant used to differentiate between upload traffic and download traffic

See Also:
Constant Field Values

observer

private FTPClientObserver observer

serverhost

private java.net.InetAddress serverhost

localhost

private java.net.InetAddress localhost

control_port

private int control_port

dataHost

private byte[] dataHost

dataPort

private byte[] dataPort

dataType

private int dataType

dataTypeLength

private int dataTypeLength

dataMode

private int dataMode

dataStructure

private int dataStructure

connected

private boolean connected

ctrlIn

private java.io.BufferedReader ctrlIn

ctrlOut

private java.io.PrintWriter ctrlOut

dataIn

private java.io.InputStream dataIn

dataOut

private java.io.OutputStream dataOut

locale

private java.util.Locale locale
Constructor Detail

FTPClient

public FTPClient()
Constructs a new instance of this class.

Since:
v1.0

FTPClient

public FTPClient(java.util.Locale locale)
Constructs a new instance of this class using the provided Locale for internationalization of FTPReplys... if avaiable. Talking about availability, if you have some time (ca. 10 minutes !) you might translate the 40 (!) sentences into your own language. Just e-mail me to jiglesias@users.sourceforge.net. MANY THANKS IN ADVANCE !

Since:
v1.0

FTPClient

public FTPClient(java.lang.String server)
          throws java.io.IOException,
                 FTPException
Constructs a new instance of this class that will try to connect to the server through the DEFAULT_FTP_PORT.

Since:
v1.0

FTPClient

public FTPClient(java.lang.String server,
                 java.util.Locale locale)
          throws java.io.IOException,
                 FTPException
Constructs a new instance of this class that will try to connect to the server through the DEFAULT_FTP_PORT.

Since:
v1.0

FTPClient

public FTPClient(java.lang.String server,
                 int port)
          throws java.io.IOException,
                 FTPException
Constructs a new instance of this class that will try to connect to the server througn the provided port.

Since:
v1.0

FTPClient

public FTPClient(java.lang.String server,
                 int port,
                 java.util.Locale locale)
          throws java.io.IOException,
                 FTPException
Constructs a new instance of this class that will try to connect to the server througn the provided port.

Since:
v1.0

FTPClient

public FTPClient(java.lang.String server,
                 java.lang.String user,
                 java.lang.String pass)
          throws java.io.IOException,
                 FTPException
Constructs a new instance of this class that will try to connect to the server through the DEFAULT_FTP_PORT, and try to log in using user and pass login information.

Since:
v1.0

FTPClient

public FTPClient(java.lang.String server,
                 java.lang.String user,
                 java.lang.String pass,
                 java.util.Locale locale)
          throws java.io.IOException,
                 FTPException
Constructs a new instance of this class that will try to connect to the server through the DEFAULT_FTP_PORT, and try to log in using user and pass login information.

Since:
v1.0

FTPClient

public FTPClient(java.lang.String server,
                 int port,
                 java.lang.String user,
                 java.lang.String pass)
          throws java.io.IOException,
                 FTPException
Constructs a new instance of this class that will try to connect to the server through the provided port, and try to log in using user and pass login information.

Since:
v1.0

FTPClient

public FTPClient(java.lang.String server,
                 int port,
                 java.lang.String user,
                 java.lang.String pass,
                 java.util.Locale locale)
          throws java.io.IOException,
                 FTPException
Constructs a new instance of this class that will try to connect to the server through the provided port, and try to log in using user and pass login information.

Since:
v1.0
Method Detail

setObserver

public void setObserver(FTPClientObserver observer)
Sets the observer of this object to be the one passed as parameter. In order to keep the class thread safe (and because I don't see any reason to have more than one observer), only one FTPClientObserver is allowed per FTPClient

Since:
v1.0

hasObserver

public boolean hasObserver()
Tells if this instance is currently being observed.

Since:
v1.0

getObserver

public FTPClientObserver getObserver()
Returns the current observer of this instance. In order to keep the class thread safe (and because I don't see any reason to have more than one observer), only one FTPClientObserver is allowed per FTPClient

Since:
v1.0

removeObserver

public void removeObserver()
Removes the current observer of this instance, if any. In order to keep the class thread safe (and because I don't see any reason to have more than one observer), only one FTPClientObserver is allowed per FTPClient

Since:
v1.0

broadcastReply

protected void broadcastReply(FTPReply reply)
Broadcasts the reply received from the server to the current observer, if any.

Since:
v1.0

broadcastCommand

protected void broadcastCommand(java.lang.String command)
Broadcasts the command sent to the server to the current observer, if any.

Since:
v1.0

dataReceived

protected void dataReceived(int bytes)
Broadcasts the amount of data received from the server to the observer, if any.

Since:
v1.0

dataSent

protected void dataSent(int bytes)
Broadcasts the amount of data received from the server to the observer, if any.

Since:
v1.0

sendFTPCommand

protected void sendFTPCommand(java.lang.String command)
                       throws java.io.IOException
Writes the command to the control stream and nofifies the observer (if it exists).

Since:
v1.0

readFTPReply

protected FTPReply readFTPReply()
                         throws java.io.IOException
Reads replies sent by FTP server on the control stream and notifies the observer (if it exists).

Since:
v1.0

writeLineToControlConnection

protected void writeLineToControlConnection(java.lang.String line)
                                     throws java.io.IOException
Writes a line to the control connection. Usual methods won't call this method directly, but through sendFTPCommand(String).

Since:
v1.0

readLineFromControlConnection

protected java.lang.String readLineFromControlConnection()
                                                  throws java.io.IOException
Reads a line from the control connection and returns it without any change. Usual methods won't call this method directly, but through readFTPReply.

Since:
v1.0

open

public void open(java.lang.String server)
          throws java.io.IOException,
                 FTPException,
                 java.net.UnknownHostException
Connects to the server through the DEFAULT_FTP_PORT.

Since:
v1.0

open

public void open(java.lang.String server,
                 int port)
          throws java.io.IOException,
                 FTPException,
                 java.net.UnknownHostException
Connects to the server through the provided port.

Since:
v1.0

isConnected

public boolean isConnected()
Returns true if a control connection is currently opened between this client and a FTP server, false else.

Since:
v1.0

isConnected

protected void isConnected(boolean isIt)
Sets the current status of the control connection to the value provided as parameter.

Since:
v1.0

login

public void login(java.lang.String user,
                  java.lang.String pass)
           throws java.io.IOException,
                  FTPException
Log to the current server using the provided login information. This is the first method to call on a server just after connecting to it.

Since:
v1.0

doUSERCommand

private int doUSERCommand(java.lang.String user)
                   throws java.io.IOException,
                          FTPException
Utility routine that takes care to send user information to the server and treat it's answer. Called before going along with password or account information.

Since:
v1.0

doPASSCommand

private int doPASSCommand(java.lang.String pass)
                   throws java.io.IOException,
                          FTPException
Utility routine that takes care to send password information to the server and treat it's answer. Called before going along with (optional) account information.

Since:
v1.0

setAccount

public void setAccount(java.lang.String value)
                throws java.io.IOException,
                       FTPException
The account data is used to indentify user's account, but is not necessarily related to the username used to log in, as some sites may require an account for login and others only for specific access, such as storing files. In the latter, the command may arrive at any time.

Since:
v1.0

logout

public void logout()
            throws java.io.IOException,
                   FTPException
This method terminates a user, flushing all I/O and account information, except to allow any transfer in progress to be completed. All parameters are reset to the default settings and the control connection is left open, leaving the control connection in the identical state which a user finds himself immediately after the control connection is opened using one of the open methods. A login call may be expected to follow. If no login call is supposed to be taken after this method, then close may be a better guess.

Since:
v1.0

setDataPort

public void setDataPort(short port)
                 throws java.io.IOException,
                        FTPException
Defines the HOST-PORT specification for the data port to be used in data connection. There are defaults for both the user and server data ports, and under normal circumstances this command and its reply are not needed. IF this command is used, the argument is the concatenation of a 32-bit internet host address and a 16-bit TCP port address.

Since:
v1.0

setDataPort

public void setDataPort(int host,
                        short port)
                 throws java.io.IOException,
                        FTPException
Defines the HOST-PORT specification for the data port to be used in data connection. There are defaults for both the user and server data ports, and under normal circumstances this command and its reply are not needed. IF this command is used, the argument is the concatenation of a 32-bit internet host address and a 16-bit TCP port address.

Since:
v1.0

setDataPort

public void setDataPort(byte host_1,
                        byte host_2,
                        byte host_3,
                        byte host_4,
                        byte port_1,
                        byte port_2)
                 throws java.io.IOException,
                        FTPException
Defines the HOST-PORT specification for the data port to be used in data connection. There are defaults for both the user and server data ports, and under normal circumstances this command and its reply are not needed. IF this command is used, the argument is the concatenation of a 32-bit internet host address and a 16-bit TCP port address.

Since:
v1.0

getDataPort

public byte[] getDataPort()
Returns the HOST-PORT used for the data connection.

Since:
v1.0

getDataType

public int getDataType()
Returns the current data type manipulated, that is one of FTPClient.ASCII_DATA_TYPE (default value), FTPClient.EBCDIC_DATA_TYPE, FTPClient.IMAGE_DATA_TYPE, FTPClient.LOCAL_DATA_TYPE.

Since:
v1.0

setDataType

public void setDataType(int type)
                 throws java.io.IOException,
                        FTPException,
                        java.lang.IllegalArgumentException
Data representations are handled in FTP by a user specifying a representation type. This type may implicitly (as ASCII or EBCDIC) or explicitly (as in Local byte) define a byte size for interpretation which is referred to as the "logical byte size". Note that this has nothing to do with the byte size used for transmission over the data connection, called the "transfer byte size", and the two should not be confused.

Since:
v1.0

setDataType

public void setDataType(int type,
                        int bytes)
                 throws java.io.IOException,
                        FTPException,
                        java.lang.IllegalArgumentException
Works just as setDataType (int), except that if the type is FTPClient.LOCAL_DATA_TYPE, then the second parameter (which is useless for the other types) must be the "logical byte size".

Since:
v1.0

getDataStructure

public int getDataStructure()
Returns the current data structure manipulated, that is one of FTPClient.FILE_DATA_STRUCTURE (default value), FTPClient.RECORD_DATA_STRUCTURE, FTPClient.PAGE_DATA_STRUCTURE.

Since:
v1.0

setDataStructure

public void setDataStructure(int structure)
                      throws java.io.IOException,
                             FTPException,
                             java.lang.IllegalArgumentException
In addition to different representation types, FTP allows the structure of a file to be specified. Both FILE and RECORD structures are accepted for "text" files.

Since:
v1.0

getDataTransferMode

public int getDataTransferMode()
Returns the data transmission mode currently used, that is one of FTPClient.STREAM_DATA_TRANSMISSION_MODE (default value), FTPClient.BLOCK_DATA_TRANSMISSION_MODE, FTPClient.COMPRESSED_DATA_TRANSMISSION_MODE.

Since:
v1.0

setDataTransferMode

public void setDataTransferMode(int mode)
                         throws java.io.IOException,
                                FTPException,
                                java.lang.IllegalArgumentException
There are three transmission mode available, one which formats the data and allows for restart procedures; one which also compresses the data for efficient transfer; and one which passes the data with little or no processing. in this last case the mode interacts with the structure attribute to determine the type of processing. In the compressed mode, the representation type determines the filler byte.

Since:
v1.0

setPassive

public byte[] setPassive()
                  throws java.io.IOException,
                         FTPException
This command requests the server-DTP to "listen" on a data port (which is not its default data port) and to wait for a connection rather that initiate one upon receipt of a transfer command.

Since:
v1.0

close

public void close()
           throws java.io.IOException,
                  FTPException
This method terminates a user and if file transfer is not in progress, the server closes the control connection. If file transfer is in progress, the connection will remain open for result response and the server will then close it. If the user-process is transferring files for several users, but does not wish to close and then reopen connections for each, the logout followed by the login methods should be called instead.

Since:
v1.0

getFileNames

public java.lang.String[] getFileNames()
                                throws java.io.IOException,
                                       FTPException
Returns a directory listing for the current working directory.

Since:
v1.0

getFileNames

public java.lang.String[] getFileNames(java.lang.String pathname)
                                throws java.io.IOException,
                                       FTPException
Returns a directory listing for the path provided as parameter. An empty String argument implies the current directory.

Since:
v1.0

getFileDescriptors

public RemoteFile[] getFileDescriptors()
                                throws java.io.IOException,
                                       FTPException
Returns the complete description of the files in the current working directory.

Since:
v1.0

getFileDescriptors

public RemoteFile[] getFileDescriptors(java.lang.String pathname)
                                throws java.io.IOException,
                                       FTPException
Returns the complete description of the files in the directory specified by the path argument. An empty String argument implies the current directory.

Since:
v1.0

getServerSystemName

public java.lang.String getServerSystemName()
                                     throws java.io.IOException,
                                            FTPException
Returns the type of operating system at the server, one of the system names listed in the current version of the 'Assigned Numbers Document' (as of 31-jul-00 : RFC1700).

Since:
v1.0

getServerStatus

public java.lang.String getServerStatus()
                                 throws java.io.IOException,
                                        FTPException
Returns the status response from the server. This method may be called during a file transfer in which case the server will respond with the status of the operation progress, or it may be sent between file transfers.

Since:
v1.0

getServerStatus

public java.lang.String getServerStatus(java.lang.String pathname)
                                 throws java.io.IOException,
                                        FTPException
Returns the status response from the server. This method may be called during a file transfer in which case the server will respond with the status of the operation progress, or it may be sent between file transfers. In the latter case, an argument may be passed. If the argument is a pathname, the command is analogous to the getFileDescriptors. Programmer using this package should track FTPReply.COMMAND_NOT_IMPLEMENTED_CODE FTPExceptions that this method may throw, because (at least some versions of) Solaris' FTP server don't seem to know about the STAT command.

Since:
v1.0

putFile

public void putFile(java.io.InputStream data,
                    java.lang.String pathname)
             throws java.io.IOException,
                    FTPException
This command causes the server-DTP to accept the data transferred and to store the data as a file at the server site. If the file specified in the pathname exists at the server site, then its contents shall be replaced by the data being transferred. A new file is created at the server site if the file specified in the pathname does not already exist.

Since:
v1.0

putUniqueFile

public java.lang.String putUniqueFile(java.io.InputStream data)
                               throws java.io.IOException,
                                      FTPException
This command behaves like putFile (InputStream, String) except that the resultant file is to be created in the current directory nder a name unique to that directory. Returns the name generated.

Since:
v1.0

appendToFile

public void appendToFile(java.io.InputStream data,
                         java.lang.String pathname)
                  throws java.io.IOException,
                         FTPException
This command causes the server-DTP to accept the data transferred and to store the data in a file at the server site. If the file specified in the pathname exists at the server site, then the data shall be appended to that file; otherwise the file specified in the pathname shall be created at the server site.

Since:
v1.0

downloadData

private void downloadData(java.io.InputStream in,
                          java.io.OutputStream out)
                   throws java.io.IOException
Transfers all data coming from server to the local host in a format that corresponds to the one set with setDataType(int).

Since:
v1.0

uploadData

private void uploadData(java.io.InputStream in,
                        java.io.OutputStream out)
                 throws java.io.IOException
Transfers all data going from local host to the server in a format that corresponds to the one set with setDataType(int).

Since:
v1.0

transferData

private void transferData(java.io.InputStream in,
                          java.io.OutputStream out)
                   throws java.io.IOException
Transfers all data coming from in to out in a format that corresponds to the one set with setDataType(int).

Since:
v1.0

transferASCIIData

private void transferASCIIData(java.io.InputStream in,
                               java.io.OutputStream out,
                               int direction)
                        throws java.io.IOException
Transfers all data coming from in to out in ASCII format.

Since:
v1.0

transferEBCDICData

private void transferEBCDICData(java.io.InputStream in,
                                java.io.OutputStream out,
                                int direction)
                         throws java.io.IOException
Transfers all data coming from in to out in EBCDIC format.

Since:
v1.0

transferImageData

private void transferImageData(java.io.InputStream in,
                               java.io.OutputStream out,
                               int direction)
                        throws java.io.IOException
Transfers all data coming from in to out in Image format.

Since:
v1.0

transferLocalData

private void transferLocalData(java.io.InputStream in,
                               java.io.OutputStream out,
                               int direction)
                        throws java.io.IOException
Transfers all data coming from in to out in Local format.

Since:
v1.0

allocateSpace

public void allocateSpace(int bytes)
                   throws java.io.IOException,
                          FTPException
This command may be required by some servers to reserve sufficient storage to accomodate the new file to be transferred. The argument shall be a decimal integer representing the number of bytes of storage to be reserved for the file.

Since:
v1.0

allocateSpace

public void allocateSpace(int space,
                          int size)
                   throws java.io.IOException,
                          FTPException
This command works just as allocateSpace (int), except that it allows to set a second (optional) parameter that may be required for files sent with record or page structure : a maximum record or page size.

Since:
v1.0

getFile

public void getFile(java.io.OutputStream destination,
                    java.lang.String pathname)
             throws java.io.IOException,
                    FTPException
This command causes the server-DTP to transfer a copy of the file, specified in the pathname, to this client. The status and contents of the file at the server site shall be unaffected.

Since:
v1.0

getFileFrom

public void getFileFrom(java.io.OutputStream destination,
                        java.lang.String pathname,
                        int position)
                 throws java.io.IOException,
                        FTPException
The position argument field represents the server marker at which file transfer is to be restarted. This command skips over the file to the specified data checkpoint.

Since:
v1.0

renameFile

public void renameFile(java.lang.String from,
                       java.lang.String to)
                throws java.io.IOException,
                       FTPException
This command causes a file to be renamed from its old pathname to its new pathname.

Since:
v1.0

doRNFRCommand

private void doRNFRCommand(java.lang.String from)
                    throws java.io.IOException,
                           FTPException
Utility routine that takes care to send current name information to the server and treat it's answer in order to rename it. Called before going along with rename to information.

Since:
v1.0

doRNTOCommand

private void doRNTOCommand(java.lang.String to)
                    throws java.io.IOException,
                           FTPException
Utility routine that takes care to send new name information to the server and treat it's answer in order to rename a file. Called after sendRNFRCommand method.

Since:
v1.0

deleteFile

public void deleteFile(java.lang.String pathname)
                throws java.io.IOException,
                       FTPException
This command causes the file specified as the pathname parameter to be deleted at the server site. This doesn't provide any kind of extra level of protection, e.g., "Do you really wish to delete?" message.

Since:
v1.0

abortCommand

public void abortCommand()
                  throws java.io.IOException,
                         FTPException
This command tells the server to abort the previous FTP service command and any associated transfer of data. The abort command may require "special action" to force recognition by the server. No action is to be taken if the previous command has been completed (including data transfer).

Since:
v1.0

prepareDataConnection

private java.net.ServerSocket prepareDataConnection(int direction)
                                             throws java.io.IOException,
                                                    FTPException
Performs the first half of data connection establishment : Opens a new ServerSocket on the local host and tells the FTP Server on which port to connect.

Since:
v1.0

prepareDataConnection

private java.net.ServerSocket prepareDataConnection(short usePort)
                                             throws java.io.IOException,
                                                    FTPException
Performs the first half of data connection establishment : Opens a new ServerSocket on the local host and tells the FTP Server on which port to connect.

Since:
v1.0

getDataInputStream

private java.io.InputStream getDataInputStream(java.net.ServerSocket localSocket)
                                        throws java.io.IOException
Performs the second half of data connection establishment : a Socket is ready on local host, the server is knocking at that door. Accepts connection, opens and returns the Stream.

Since:
v1.0

getDataOutputStream

private java.io.OutputStream getDataOutputStream(java.net.ServerSocket localSocket)
                                          throws java.io.IOException
Performs the second half of data connection establishment : a Socket is ready on local host, the server is knocking at that door. Accepts connection, opens and returns the Stream.

Since:
v1.0

makeDirectory

public void makeDirectory(java.lang.String pathname)
                   throws java.io.IOException,
                          FTPException
This command causes the directory specified in the pathname to be created as a directory (if the pathname is absolute) or as a subdirectory of the current working directory (if the pathname is relative).

Since:
v1.0

removeDirectory

public void removeDirectory(java.lang.String pathname)
                     throws java.io.IOException,
                            FTPException
This command cau