| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecttribble.net.ftp.FTPClientAdapter
public abstract class FTPClientAdapter
Simple FTP client base class. Allows clients to establish FTP connections, send and receive files, get remote directory listings, etc.
This base class provides a framework upon which to build working FTP client implementations. References IETF RFC 959 - File Transfer Protocol (FTP)
        Copyright ©2006-2010 by David R. Tribble, all rights reserved.
        Permission is granted to any person or entity except those designated
        by the United States Department of State as a terrorist, or terrorist
        government or agency, to use and distribute this source code provided
        that the original copyright notice remains present and unaltered.
FTPClient| Field Summary | |
|---|---|
| protected  int | m_bufSizeData transfer buffer length. | 
| protected  int | m_cmdPortRemote FTP port number. | 
| protected  int | m_dataPort | 
|  java.io.PrintStream | m_debugOutEnable debug tracing. | 
| protected  java.lang.String | m_hostNameRemote FTP host name. | 
| protected  long | m_inBytesNumber of input bytes read. | 
| protected  boolean | m_isConnectedThis session has connected to the remote FTP system. | 
| protected  boolean | m_isLoggedOnFTP user is logged into the FTP session. | 
| protected  java.io.File | m_localDirCurrent local working directory. | 
| protected  long | m_outBytesNumber of output bytes written. | 
| protected  boolean | m_passiveModeTransfer mode is passive. | 
| protected  java.lang.String | m_passwordUser password. | 
| protected  java.lang.String | m_remoteDirCurrent remote working directory. | 
| protected  boolean | m_stopStop/interrupt execution flag. | 
| protected  boolean | m_textModeTransfer files as text (ASCII) mode, not binary. | 
| protected  int | m_timeOutI/O time-out (seconds). | 
| protected  java.lang.String | m_userIDUser-ID. | 
| Constructor Summary | |
|---|---|
| FTPClientAdapter()Default constructor. | |
| Method Summary | |
|---|---|
|  void | appendFile(java.io.File src,
           java.lang.String dst)Append (send) a file from the local system to a file on the remote FTP system. | 
| abstract  void | appendFile(java.io.InputStream in,
           java.lang.String dst)Append (send) a file from the local system to a file on the remote FTP system. | 
|  void | appendFile(java.lang.String src,
           java.lang.String dst)Append (send) a file from the local system to a file on the remote FTP system. | 
| abstract  void | connect()Connect to the remote FTP system. | 
| abstract  void | createDirectory(java.lang.String dir)Create a directory on the remote FTP system. | 
| abstract  void | disconnect()Disconnect from the remote FTP system. | 
| protected  void | finalize()Finalization. | 
|  int | getCommandPort()Retrieve the FTP command port number. | 
|  int | getDataPort()Retrieve the FTP data port number. | 
| abstract  void | getDirectoryList(java.lang.String path,
                 int max,
                 java.io.OutputStream out)Get (receive) a directory listing from the remote FTP system. | 
|  void | getDirectoryList(java.lang.String path,
                 java.io.OutputStream out)Get (receive) a directory listing from the remote FTP system. | 
|  java.util.ArrayList<java.lang.String> | getDirectoryNames(java.lang.String path)Get (receive) a list of filenames in a directory on the remote FTP system. | 
|  java.util.ArrayList<java.lang.String> | getDirectoryNames(java.lang.String path,
                  int max)Get (receive) a list of filenames in a directory on the remote FTP system. | 
| abstract  void | getDirectoryNames(java.lang.String path,
                  int max,
                  java.io.OutputStream out)Get (receive) a list of filenames in a directory on the remote FTP system. | 
|  void | getDirectoryNames(java.lang.String path,
                  java.io.OutputStream out)Get (receive) a list of filenames in a directory on the remote FTP system. | 
|  void | getFile(java.lang.String src,
        java.io.File dst)Get (receive) a file from the remote FTP system to the local system. | 
| abstract  void | getFile(java.lang.String src,
        java.io.OutputStream out)Get (receive) a file from the remote FTP system to the local system. | 
|  void | getFile(java.lang.String src,
        java.lang.String dst)Get (receive) a file from the remote FTP system to the local system. | 
| abstract  void | getHelp(java.io.OutputStream out)Get (receive) a help listing of supported FTP commands from the remote FTP system. | 
|  java.lang.String | getHost()Retrieve the remote FTP host name. | 
|  long | getInputByteCount()Retrieve the number of bytes read from the input data port so far. | 
|  java.lang.String | getLocalDir()Retrieve the working directory of the local system. | 
|  long | getOutputByteCount()Retrieve the number of bytes written to the output data port so far. | 
|  java.lang.String | getPassword()Retrieve the user password. | 
|  java.lang.String | getRemoteDir()Retrieve the current working directory of the remote FTP system. | 
| abstract  void | getStatus(java.io.OutputStream out)Retrieve the current status of the remote FTP system. | 
| abstract  void | getSystemInfo(java.io.OutputStream out)Retrieve the identity information of the remote FTP system. | 
|  int | getTimeOut()Retrieve the FTP I/O time-out. | 
|  java.lang.String | getUserID()Retrieve the user-ID. | 
| static boolean | isAbsoluteFilename(java.io.File file)Determine if a filename is absolute or not. | 
|  boolean | isConnected()Determine if this client is connected to the remote FTP system. | 
|  boolean | isLoggedIn()Determine if this client is logged to the remote FTP system. | 
|  void | login()Log on to the remote FTP system. | 
| abstract  void | login(java.lang.String user,
      java.lang.String pwd)Log on to the remote FTP system. | 
| abstract  void | ping()Pings the remote FTP system. | 
|  void | putFile(java.io.File src,
        java.lang.String dst)Put (send) a file from the local system to the remote FTP system. | 
| abstract  void | putFile(java.io.InputStream in,
        java.lang.String dst)Put (send) a file from the local system to the remote FTP system. | 
|  void | putFile(java.lang.String src,
        java.lang.String dst)Put (send) a file from the local system to the remote FTP system. | 
| abstract  void | removeDirectory(java.lang.String dir)Remove a directory on the remote FTP system. | 
| abstract  void | removeFile(java.lang.String file)Remove a file on the remote FTP system. | 
| abstract  void | rename(java.lang.String from,
       java.lang.String to)Rename a file or directory on the remote FTP system. | 
|  void | resetStop()Reset the interrupt signal set by a previous call to stop(). | 
|  int | setBufferSize(int len)Set the size of the FTP data transfer buffer. | 
|  void | setCommandPort(int port)Set the remote FTP command port number. | 
|  void | setDataPort(int port)Set the remote FTP data port number. | 
|  void | setHost(java.lang.String host)Set the remote FTP host (system) name. | 
|  void | setLocalDir(java.lang.String dir)Set the working directory on the local system. | 
|  boolean | setPassive(boolean flag)Set this FTP client to operate (or not) in passive data transfer mode. | 
|  void | setPassword(java.lang.String pwd)Set the user password. | 
|  java.lang.String | setRemoteDir(java.lang.String dir)Set the working directory on the remote FTP system. | 
| abstract  java.lang.String | setRemoteDirUp()Set the working directory on the remote FTP system to the parent directory of the current working directory. | 
|  boolean | setTextMode(boolean flag)Set the transfer mode to text (ASCII) or binary. | 
|  void | setTimeOut(int secs)Set the remote FTP I/O time-out. | 
|  void | setUserID(java.lang.String id)Set the user name (user-ID). | 
|  void | stop()Signal the current FTP operation to be interrupted and to terminate prematurely. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Methods inherited from interface tribble.net.ftp.FTPSimpleClientI | 
|---|
| getDirectoryNames | 
| Field Detail | 
|---|
public java.io.PrintStream m_debugOut
protected java.lang.String m_hostName
protected int m_cmdPort
protected int m_dataPort
protected int m_timeOut
protected int m_bufSize
protected java.lang.String m_userID
protected java.lang.String m_password
protected java.lang.String m_remoteDir
protected java.io.File m_localDir
protected boolean m_passiveMode
protected boolean m_textMode
protected boolean m_isConnected
protected boolean m_isLoggedOn
protected volatile boolean m_stop
protected volatile long m_inBytes
protected volatile long m_outBytes
| Constructor Detail | 
|---|
public FTPClientAdapter()
| Method Detail | 
|---|
public static boolean isAbsoluteFilename(java.io.File file)
Note that this handles Win32 absolute pathnames without leading drive letters properly (e.g., "c:\foo.txt" and "\foo.txt" are both absolute pathnames). This corrects an oversight in the standard Java library implementation.
file - A filename to check.
public void stop()
 Once this method has been called, the interrupt signal can be cleared by
 calling resetStop().
resetStop()public void resetStop()
stop().
stop()public long getInputByteCount()
This method can be called from a separate thread while an FTP operation is being performed on this object to check the progress of the operation.
public long getOutputByteCount()
This method can be called from a separate thread while an FTP operation is being performed on this object to check the progress of the operation.
public java.lang.String getHost()
getHost in interface FTPSimpleClientIsetHost()public void setHost(java.lang.String host)
setHost in interface FTPSimpleClientIhost - FTP system host name or IP address.getHost()public int getCommandPort()
getCommandPort in interface FTPSimpleClientIsetCommandPort(), 
getDataPort()public void setCommandPort(int port)
setCommandPort in interface FTPSimpleClientIport - FTP command port number.  (The default FTP port is 21.)getCommandPort(), 
setDataPort()public int getDataPort()
getDataPort in interface FTPSimpleClientIsetDataPort(), 
getCommandPort()public void setDataPort(int port)
setDataPort in interface FTPSimpleClientIport - FTP data port number.  Setting this to zero or a negative number causes
 the data ports to be chosen (randomly) by the local system when operating
 in non-passive mode.  (The default FTP port is 0.)getDataPort(), 
setCommandPort()public int getTimeOut()
getTimeOut in interface FTPSimpleClientIsetTimeOut(), 
getCommandPort(), 
getDataPort()public void setTimeOut(int secs)
setTimeOut in interface FTPSimpleClientIsecs - FTP I/O time-out, in seconds.
 (The default setting is 30.)getTimeOut(), 
setCommandPort(), 
setDataPort()public int setBufferSize(int len)
setBufferSize in interface FTPSimpleClientIlen - New buffer size.
 Values between 1K (1,024) and 16K (16,384) are probably optimal for most
 applications.
 Classes that extend this class may choose to ignore this setting.
java.lang.IllegalArgumentException - (unchecked)
 Thrown if len is less than 1.appendFile(), 
getFile(), 
putFile()public java.lang.String getUserID()
getUserID in interface FTPSimpleClientIsetUserID()public void setUserID(java.lang.String id)
setUserID in interface FTPSimpleClientIid - User-ID.getUserID()public java.lang.String getPassword()
getPassword in interface FTPSimpleClientIsetPassword()public void setPassword(java.lang.String pwd)
setPassword in interface FTPSimpleClientIpwd - User password.getPassword()public boolean setPassive(boolean flag)
setPassive in interface FTPSimpleClientIflag - If true, the data transfer mode is set to passive, otherwise it is set to
 non-passive (active listen) mode.
public abstract void connect()
                      throws java.io.IOException
connect in interface FTPSimpleClientIjava.io.IOException - Thrown if unable to connect to the remote FTP system.disconnect()public abstract void disconnect()
IOException.
disconnect in interface FTPSimpleClientIconnect()public boolean isConnected()
isConnected in interface FTPSimpleClientIconnect(), 
disconnect()
public void login()
           throws java.io.IOException
login in interface FTPSimpleClientIjava.io.IOException - Thrown if an error occurs.connect(), 
setUserID(), 
setPassword()
public abstract void login(java.lang.String user,
                           java.lang.String pwd)
                    throws java.io.IOException
login in interface FTPClientIuser - FTP user-ID for the remote system.pwd - User password.  This can be empty ("").
java.io.IOException - Thrown if an error occurs.login(), 
connect()public boolean isLoggedIn()
isLoggedIn in interface FTPSimpleClientIlogin()public boolean setTextMode(boolean flag)
setTextMode in interface FTPSimpleClientIflag - If true, the transfer mode is set to text (ASCII), otherwise it is set
 to binary.
public abstract void ping()
                   throws java.io.IOException
ping in interface FTPClientIjava.io.IOException - Thrown if an error occurs, e.g., the FTP connection is broken.
public abstract void getSystemInfo(java.io.OutputStream out)
                            throws java.io.IOException
getSystemInfo in interface FTPClientIout - Output stream to which the identification information is to be written.
java.io.IOException - Thrown if an I/O error occurs.
public abstract void getStatus(java.io.OutputStream out)
                        throws java.io.IOException
getStatus in interface FTPClientIout - Output stream to which the status is to be written.
java.io.IOException - Thrown if an I/O error occurs.
public abstract void getHelp(java.io.OutputStream out)
                      throws java.io.IOException
getHelp in interface FTPClientIout - Output stream to which the help listing is to be written.
java.io.IOException - Thrown if an error occurs.
public java.lang.String setRemoteDir(java.lang.String dir)
                              throws java.io.IOException
setRemoteDir in interface FTPSimpleClientIdir - Remote directory name.
java.io.IOException - Thrown if an error occurs.setRemoteDirUp(), 
getRemoteDir(), 
setLocalDir()
public abstract java.lang.String setRemoteDirUp()
                                         throws java.io.IOException
setRemoteDirUp in interface FTPSimpleClientIjava.io.IOException - Thrown if an error occurs.getRemoteDir(), 
setRemoteDir(), 
setLocalDir()
public java.lang.String getRemoteDir()
                              throws java.io.IOException
getRemoteDir in interface FTPSimpleClientIjava.io.IOException - Thrown if an error occurs.setRemoteDir(), 
setRemoteDirUp(), 
getLocalDir()
public void setLocalDir(java.lang.String dir)
                 throws java.io.IOException
setLocalDir in interface FTPSimpleClientIdir - Local directory name.
java.io.IOException - Thrown if an error occurs.getLocalDir(), 
setRemoteDir(), 
setRemoteDirUp()
public java.lang.String getLocalDir()
                             throws java.io.IOException
getLocalDir in interface FTPSimpleClientIjava.io.IOException - Thrown if an error occurs.setLocalDir(), 
getRemoteDir()
public void getFile(java.lang.String src,
                    java.lang.String dst)
             throws java.io.IOException
getFile in interface FTPClientIsrc - Remote source filename.  If this does not contain a directory prefix, the
 current remote working directory is assumed.dst - Local source filename.  If this does not contain a directory prefix, the
 current local working directory is assumed.  This may be null, in which
 case the base filename of src (without the directory prefix) is
 used.
java.io.IOException - Thrown if the file could not be transmitted or if any other error occurs.getFile(), 
getFile(), 
putFile()
public void getFile(java.lang.String src,
                    java.io.File dst)
             throws java.io.IOException
getFile in interface FTPSimpleClientIsrc - Remote source filename.  If this does not contain a directory prefix, the
 current remote working directory is assumed.dst - Local source filename.  If this does not contain a directory prefix, the
 current local working directory is assumed.  This may be null, in which
 case the base filename of src (without the directory prefix) is
 used.
java.io.IOException - Thrown if the file could not be transmitted or if any other error occurs.getFile(), 
getFile(), 
putFile()
public abstract void getFile(java.lang.String src,
                             java.io.OutputStream out)
                      throws java.io.IOException
getFile in interface FTPSimpleClientIsrc - Remote source filename.  If this does not contain a directory prefix, the
 current remote working directory is assumed.out - Output stream to write the contents of the file retrieved from the remote
 FTP system to.  Note that this stream is flushed but is not closed
 after the contents have been transmitted.
java.io.IOException - Thrown if the file could not be transmitted or if any other error occurs.getFile(), 
getFile(), 
putFile()
public void putFile(java.lang.String src,
                    java.lang.String dst)
             throws java.io.IOException
putFile in interface FTPClientIsrc - Local source filename.  If this does not contain a directory prefix, the
 current local working directory is assumed.dst - Remote target filename.  If this does not contain a directory prefix, the
 current remote working directory is assumed.  This may be null, in which
 case the base filename of src (without the directory prefix) is
 used.
java.io.IOException - Thrown if the file could not be transmitted or if any other error occurs.putFile(), 
putFile(), 
getFile()
public void putFile(java.io.File src,
                    java.lang.String dst)
             throws java.io.IOException
putFile in interface FTPSimpleClientIsrc - Local source filename.  If this does not contain a directory prefix, the
 current local working directory is assumed.dst - Remote target filename.  If this does not contain a directory prefix, the
 current remote working directory is assumed.  This may be null, in which
 case the base filename of src (without the directory prefix) is
 used.
java.io.IOException - Thrown if the file could not be transmitted or if any other error occurs.putFile(), 
putFile(), 
getFile()
public abstract void putFile(java.io.InputStream in,
                             java.lang.String dst)
                      throws java.io.IOException
putFile in interface FTPSimpleClientIin - Input stream containing the contents of the file to send to the remote FTP
 system.  Note that this stream is not closed after the contents
 have been transmitted.dst - Remote target filename.  If this does not contain a directory prefix, the
 current remote working directory is assumed.  This may be null, in which
 case the base filename of src (without the directory prefix) is
 used.
java.io.IOException - Thrown if the file could not be transmitted or if any other error occurs.putFile(), 
putFile(), 
getFile()
public void appendFile(java.lang.String src,
                       java.lang.String dst)
                throws java.io.IOException
appendFile in interface FTPClientIsrc - Local source filename.  If this does not contain a directory prefix, the
 current local working directory is assumed.dst - Remote target filename.  If this does not contain a directory prefix, the
 current remote working directory is assumed.  This may be null, in which
 case the base filename of src (without the directory prefix) is
 used.
java.io.IOException - Thrown if the file could not be transmitted or if any other error occurs.appendFile(), 
appendFile(), 
getFile()
public void appendFile(java.io.File src,
                       java.lang.String dst)
                throws java.io.IOException
appendFile in interface FTPSimpleClientIsrc - Local source filename.  If this does not contain a directory prefix, the
 current local working directory is assumed.dst - Remote target filename.  If this does not contain a directory prefix, the
 current remote working directory is assumed.  This may be null, in which
 case the base filename of src (without the directory prefix) is
 used.
java.io.IOException - Thrown if the file could not be transmitted or if any other error occurs.appendFile(), 
appendFile(), 
getFile()
public abstract void appendFile(java.io.InputStream in,
                                java.lang.String dst)
                         throws java.io.IOException
appendFile in interface FTPSimpleClientIin - Input stream containing the contents of the file to send to the remote FTP
 system.  Note that this stream is not closed after the contents
 have been transmitted.dst - Remote target filename.  If this does not contain a directory prefix, the
 current remote working directory is assumed.  This may be null, in which
 case the base filename of src (without the directory prefix) is
 used.
java.io.IOException - Thrown if the file could not be transmitted or if any other error occurs.appendFile(), 
appendFile(), 
getFile()
public void getDirectoryList(java.lang.String path,
                             java.io.OutputStream out)
                      throws java.io.IOException
getDirectoryList in interface FTPClientIpath - The remote directory or file name to list.  If this is empty
 (""), the current remote working directory is assumed.out - Output stream to which the directory listing is to be written.
java.io.IOException - Thrown if an error occurs.
public abstract void getDirectoryList(java.lang.String path,
                                      int max,
                                      java.io.OutputStream out)
                               throws java.io.IOException
getDirectoryList in interface FTPClientIpath - The remote directory or filename to list.  If this is empty
 (""), the current remote working directory is assumed.max - Maximum number of filenames (output lines) to list.  A value of zero (0)
 specifies that there is no maximum.out - Output stream to which the directory listing is to be written.
java.io.IOException - Thrown if an error occurs.
public void getDirectoryNames(java.lang.String path,
                              java.io.OutputStream out)
                       throws java.io.IOException
getDirectoryNames in interface FTPClientIpath - The remote directory or file name to list.  If this is empty
 (""), the current remote working directory is assumed.out - Output stream to which the directory listing is to be written.
java.io.IOException - Thrown if an error occurs.
public abstract void getDirectoryNames(java.lang.String path,
                                       int max,
                                       java.io.OutputStream out)
                                throws java.io.IOException
getDirectoryNames in interface FTPClientIpath - The remote directory or filename to list.  If this is empty
 (""), the current remote working directory is assumed.max - Maximum number of filenames to get.  A value of zero (0) specifies that
 there is no maximum.out - Output stream to which the directory listing is to be written.
java.io.IOException - Thrown if an error occurs.
public java.util.ArrayList<java.lang.String> getDirectoryNames(java.lang.String path)
                                                        throws java.io.IOException
path - The remote directory or file name to list.  If this is empty
 (""), the current remote working directory is assumed.
java.io.IOException - Thrown if an error occurs.
public java.util.ArrayList<java.lang.String> getDirectoryNames(java.lang.String path,
                                                               int max)
                                                        throws java.io.IOException
getDirectoryNames in interface FTPSimpleClientIpath - The remote directory or filename to list.  If this is empty
 (""), the current remote working directory is assumed.max - Maximum number of filenames to list.  A value of zero (0) specifies that
 there is no maximum.
java.io.IOException - Thrown if an error occurs.
public abstract void rename(java.lang.String from,
                            java.lang.String to)
                     throws java.io.IOException
rename in interface FTPSimpleClientIfrom - Old (existing) remote file or directory name to rename.to - New name to rename the remote file or directory to.
java.io.IOException - Thrown if an error occurs.
public abstract void removeFile(java.lang.String file)
                         throws java.io.IOException
removeFile in interface FTPSimpleClientIfile - Name of the file to delete.  If this specifies a relative file name, the
 file is assumed to be located in the current remote working directory.
java.io.IOException - Thrown if an error occurs.
public abstract void createDirectory(java.lang.String dir)
                              throws java.io.IOException
createDirectory in interface FTPSimpleClientIdir - Name of the directory to create.  If this specifies a relative directory
 name, the directory is created in the current remote working directory.
java.io.IOException - Thrown if an error occurs.
public abstract void removeDirectory(java.lang.String dir)
                              throws java.io.IOException
removeDirectory in interface FTPSimpleClientIdir - Name of the directory to delete.  If this specifies a relative directory
 name, the directory is assumed to be located in the current remote working
 directory.
java.io.IOException - Thrown if an error occurs.
protected void finalize()
                 throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||