Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.enterprisedt.net.ftp
Class FileTransferClient

    java.lang.Object
      com.enterprisedt.net.ftp.FileTransferClient

All Implemented Interfaces:
  FileTransferClientInterface

    public class FileTransferClient

extends java.lang.Object
implements FileTransferClientInterface

Easy to use FTP client that is thread safe and provides true FTP streams. This class is intended to replace FTPClient, which will eventually be deprecated.

Version:
  $Revision: 1.7 $
Author:
  Bruce Blackshaw

Field Summary
`protected com.enterprisedt.net.ftp.EventAggregator` | `eventAggregator`
`protected EventListener` | `listener` Event listeners
`protected ConnectionContext` | `masterContext` Context for the client that is the starting point for all new tasks.

Constructor Summary
`FileTransferClient()` Default constructor

Method Summary
`void` | `cancelAllTransfers()` Cancel current transfer if underway
`void` | `changeDirectory(java.lang.String directoryName)` Change directory on the FTP server.
`void` | `changeToParentDirectory()` Change to parent directory on the FTP server.
`protected void` | `checkConnection(boolean shouldBeConnected)` Checks if the client has connected to the server and throws an exception if it hasn't.
`void` | `connect()` Make a connection to the FTP server.
`void` | `createDirectory(java.lang.String directoryName)` Create directory on the FTP server.
`void` | `deleteDirectory(java.lang.String directoryName)` Create directory on the FTP server.
`void` | `deleteFile(java.lang.String remoteFileName)` Deletes a remote file.
`FTPFile[]` | `directoryList()` List the current directory on the FTP server.
`FTPFile[]` | `directoryList(java.lang.String directoryName)` List a directory on the FTP server.
`java.lang.String[]` | `directoryNameList()` List the names of files and directories in the current directory on the FTP server.
`java.lang.String[]` | `directoryNameList(java.lang.String directoryName, boolean isLongListing)` List the names of files and directories of a directory on the FTP server.
`void` | `disconnect()` Disconnect from the FTP server.
`void` | `disconnect(boolean immediate)` Disconnect from the FTP server.
`byte[]` | `downloadByteArray(java.lang.String remoteFileName)` Download a file from the FTP server into a byte array.
`void` | `downloadFile(java.lang.String localFileName, java.lang.String remoteFileName)` Download a file from the FTP server .
`void` | `downloadFile(java.lang.String localFileName, java.lang.String remoteFileName, WriteMode writeMode)` Download a file from the FTP server .
`FileTransferInputStream` | `downloadStream(java.lang.String remoteFileName)` Download a file from the FTP server as a stream.
`java.lang.String` | `executeCommand(java.lang.String command)` Request that the remote server execute the literal command supplied.
`boolean` | `exists(java.lang.String remoteFileName)` Determine if a remote file exists.
`AdvancedFTPSettings` | `getAdvancedFTPSettings()` Get the advanced FTP configuration parameters object
`AdvancedGeneralSettings` | `getAdvancedSettings()` Get the advanced general configuration parameters object, for none protocol specific parameters
`FTPTransferType` | `getContentType()` Get the current content type for all connections.
`boolean` | `getDetectContentType()` Get the detect content type flag
`java.util.Date` | `getModifiedTime(java.lang.String remoteFileName)` Get the modified-time of a remote file.
`java.lang.String` | `getPassword()` Get the current user password.
`java.lang.String` | `getRemoteDirectory()` Get the current remote directory.
`java.lang.String` | `getRemoteHost()` Returns the IP address or name of the remote host.
`int` | `getRemotePort()` Returns the port being connected to on the remote server.
`long` | `getSize(java.lang.String remoteFileName)` Get the size of a remote file.
`FileStatistics` | `getStatistics()` Get statistics on file transfers and deletions.
`java.lang.String` | `getSystemType()` Get a string that represents the remote system that the client is logged into.
`int` | `getTimeout()` Returns the timeout for socket connections.
`java.lang.String` | `getUserName()` Get the current user name.
`boolean` | `isConnected()` Is this client currently connected to the server?
`void` | `manualLogin()` Perform a manual login using the credentials that have been set.
`void` | `rename(java.lang.String renameFromName, java.lang.String renameToName)` Rename a remote file or directory.
`void` | `setContentType(FTPTransferType type)` Set the transfer type for all connections, either ASCII or binary.
`void` | `setDetectContentType(boolean detectContentType)` Set auto detect of filetypes on or off.
`void` | `setEventListener(EventListener listener)` Set the event listener for transfer event notification
`void` | `setPassword(java.lang.String password)` Set the password of the user to log in with.
`void` | `setRemoteHost(java.lang.String remoteHost)` Set the IP address or name of the remote host This may only be done if the client is not already connected to the server.
`void` | `setRemotePort(int remotePort)` Set the port to connect to on the remote server.
`void` | `setTimeout(int timeout)` Set the timeout for socket connections.
`void` | `setUserName(java.lang.String userName)` Set the name of the user to log in with.
`java.lang.String` | `uploadFile(java.lang.String localFileName, java.lang.String remoteFileName)` Upload a file to the FTP server.
`java.lang.String` | `uploadFile(java.lang.String localFileName, java.lang.String remoteFileName, WriteMode writeMode)` Upload a file to the FTP server.
`FileTransferOutputStream` | `uploadStream(java.lang.String remoteFileName)` Upload a file to the FTP server by writing to a stream.
`FileTransferOutputStream` | `uploadStream(java.lang.String remoteFileName, WriteMode writeMode)` Upload a file to the FTP server by writing to a stream.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### masterContext

    protected ConnectionContext masterContext

  Context for the client that is the starting point for all new tasks. If we have a change directory task, when it is completed it will update this master context and the updated context will be used for all future tasks

### eventAggregator

    protected com.enterprisedt.net.ftp.EventAggregator eventAggregator

### listener

    protected EventListener listener

  Event listeners

Constructor Detail

### FileTransferClient

    public FileTransferClient()

  Default constructor

Method Detail

### checkConnection

    protected void checkConnection(boolean shouldBeConnected)
                            throws FTPException

  Checks if the client has connected to the server and throws an exception if it hasn't. This is only intended to be used by subclasses

  Throws:
    `FTPException` - Thrown if the client has not connected to the server.

### isConnected

    public boolean isConnected()

  Is this client currently connected to the server?

  Specified by:
    `isConnected` in interface `FileTransferClientInterface`
  Returns:
    true if connected, false otherwise

### getRemoteHost

    public java.lang.String getRemoteHost()

  Returns the IP address or name of the remote host.

  Specified by:
    `getRemoteHost` in interface `FileTransferClientInterface`
  Returns:
    Returns the remote host.

### setRemoteHost

    public void setRemoteHost(java.lang.String remoteHost)
                       throws FTPException

  Set the IP address or name of the remote host This may only be done if the client is not already connected to the server.

  Specified by:
    `setRemoteHost` in interface `FileTransferClientInterface`
  Parameters:
    `remoteHost` - The IP address or name of the remote host
  Throws:
    `FTPException` - Thrown if the client is already connected to the server.

### getTimeout

    public int getTimeout()

  Returns the timeout for socket connections.

  Specified by:
    `getTimeout` in interface `FileTransferClientInterface`
  Returns:
    Returns the connection timeout in milliseconds

### setTimeout

    public void setTimeout(int timeout)
                    throws FTPException

  Set the timeout for socket connections. Can only do this if not already connected.

  Specified by:
    `setTimeout` in interface `FileTransferClientInterface`
  Parameters:
    `timeout` - the timeout to use in milliseconds
  Throws:
    `FTPException` - Thrown if the client is already connected to the server.

### getRemotePort

    public int getRemotePort()

  Returns the port being connected to on the remote server.

  Specified by:
    `getRemotePort` in interface `FileTransferClientInterface`
  Returns:
    Returns the port being connected to on the remote server.

### setRemotePort

    public void setRemotePort(int remotePort)
                       throws FTPException

  Set the port to connect to on the remote server. Can only do this if not already connected.

  Specified by:
    `setRemotePort` in interface `FileTransferClientInterface`
  Parameters:
    `remotePort` - The port to use.
  Throws:
    `FTPException` - Thrown if the client is already connected to the server.

### setContentType

    public void setContentType(FTPTransferType type)
                        throws java.io.IOException,
                               FTPException

  Set the transfer type for all connections, either ASCII or binary. Setting applies to all subsequent transfers that are initiated.

  Specified by:
    `setContentType` in interface `FileTransferClientInterface`
  Parameters:
    `type` - transfer type
  Throws:
    `FTPException`
    `java.io.IOException`
    `FTPException`

### getContentType

    public FTPTransferType getContentType()

  Get the current content type for all connections.

  Specified by:
    `getContentType` in interface `FileTransferClientInterface`
  Returns:
    transfer type

### setDetectContentType

    public void setDetectContentType(boolean detectContentType)

  Set auto detect of filetypes on or off. If on, the transfer mode is switched from ASCII to binary and vice versa depending on the extension of the file. After the transfer, the mode is always returned to what it was before the transfer was performed. The default is off. If the filetype is unknown, the transfer mode is unchanged

  Specified by:
    `setDetectContentType` in interface `FileTransferClientInterface`
  Parameters:
    `detectContentType` - true if detecting content type, false if not

### getDetectContentType

    public boolean getDetectContentType()

  Get the detect content type flag

  Specified by:
    `getDetectContentType` in interface `FileTransferClientInterface`
  Returns:
    true if we are detecting binary and ASCII transfers from the file type

### setUserName

    public void setUserName(java.lang.String userName)
                     throws FTPException

  Set the name of the user to log in with. Can only do this if not already connected.

  Specified by:
    `setUserName` in interface `FileTransferClientInterface`
  Parameters:
    `userName` - user-name to log in with.
  Throws:
    `FTPException`

### getPassword

    public java.lang.String getPassword()

  Get the current user password.

  Specified by:
    `getPassword` in interface `FileTransferClientInterface`
  Returns:
    current user password

### setPassword

    public void setPassword(java.lang.String password)
                     throws FTPException

  Set the password of the user to log in with. Can only do this if not already connected.

  Specified by:
    `setPassword` in interface `FileTransferClientInterface`
  Parameters:
    `password` - password to log in with.
  Throws:
    `FTPException`

### getUserName

    public java.lang.String getUserName()

  Get the current user name.

  Specified by:
    `getUserName` in interface `FileTransferClientInterface`
  Returns:
    current user name

### getAdvancedFTPSettings

    public AdvancedFTPSettings getAdvancedFTPSettings()

  Get the advanced FTP configuration parameters object

  Specified by:
    `getAdvancedFTPSettings` in interface `FileTransferClientInterface`
  Returns:
    advanced parameters

### getAdvancedSettings

    public AdvancedGeneralSettings getAdvancedSettings()

  Get the advanced general configuration parameters object, for none protocol specific parameters

  Specified by:
    `getAdvancedSettings` in interface `FileTransferClientInterface`
  Returns:
    advanced parameters

### setEventListener

    public void setEventListener(EventListener listener)

  Set the event listener for transfer event notification

  Specified by:
    `setEventListener` in interface `FileTransferClientInterface`
  Parameters:
    `listener` - event listener reference

### connect

    public void connect()
                 throws FTPException,
                        java.io.IOException

  Make a connection to the FTP server.

  Specified by:
    `connect` in interface `FileTransferClientInterface`
  Throws:
    `FTPException`
    `java.io.IOException`

### manualLogin

    public void manualLogin()
                     throws FTPException,
                            java.io.IOException

  Perform a manual login using the credentials that have been set. This should only be performed if auto login is disabled - normally connect() performs the login automatically.

  Throws:
    `FTPException`
    `java.io.IOException`

### getStatistics

    public FileStatistics getStatistics()

  Get statistics on file transfers and deletions.

  Specified by:
    `getStatistics` in interface `FileTransferClientInterface`
  Returns:
    FTPStatistics

### executeCommand

    public java.lang.String executeCommand(java.lang.String command)
                                    throws FTPException,
                                           java.io.IOException

  Request that the remote server execute the literal command supplied. In FTP, this is the equivalent of 'quote'. It could be used to send a SITE command to the server, e.g. "SITE recfm=FB lrecl=180 blksize=5400".

  Specified by:
    `executeCommand` in interface `FileTransferClientInterface`
  Parameters:
    `command` - command string
  Returns:
    result string returned by server
  Throws:
    `FTPException`
    `java.io.IOException`

### cancelAllTransfers

    public void cancelAllTransfers()

  Cancel current transfer if underway

  Specified by:
    `cancelAllTransfers` in interface `FileTransferClientInterface`

### getSystemType

    public java.lang.String getSystemType()
                                   throws FTPException,
                                          java.io.IOException

  Get a string that represents the remote system that the client is logged into.

  Specified by:
    `getSystemType` in interface `FileTransferClientInterface`
  Returns:
    system string
  Throws:
    `FTPException`
    `java.io.IOException`

### directoryNameList

    public java.lang.String[] directoryNameList()
                                         throws FTPException,
                                                java.io.IOException

  List the names of files and directories in the current directory on the FTP server.

  Specified by:
    `directoryNameList` in interface `FileTransferClientInterface`
  Returns:
    String[]
  Throws:
    `FTPException,` - IOException
    `FTPException`
    `java.io.IOException`

### directoryNameList

    public java.lang.String[] directoryNameList(java.lang.String directoryName,
                                                boolean isLongListing)
                                         throws FTPException,
                                                java.io.IOException

  List the names of files and directories of a directory on the FTP server.

  Specified by:
    `directoryNameList` in interface `FileTransferClientInterface`
  Parameters:
    `directoryName` - name of the directory (generally not a path). Some servers will accept a wildcard.
    `isLongListing` - true if the listing is a long format listing
  Returns:
    String[]
  Throws:
    `FTPException,` - IOException
    `FTPException`
    `java.io.IOException`

### directoryList

    public FTPFile[] directoryList()
                            throws FTPException,
                                   java.io.IOException,
                                   java.text.ParseException

  List the current directory on the FTP server.

  Specified by:
    `directoryList` in interface `FileTransferClientInterface`
  Throws:
    `FTPException,` - IOException
    `java.text.ParseException`
    `FTPException`
    `java.io.IOException`

### directoryList

    public FTPFile[] directoryList(java.lang.String directoryName)
                            throws FTPException,
                                   java.io.IOException,
                                   java.text.ParseException

  List a directory on the FTP server.

  Specified by:
    `directoryList` in interface `FileTransferClientInterface`
  Parameters:
    `directoryName` - name of the directory (generally not a path). Some servers will accept a wildcard.
  Throws:
    `FTPException,` - IOException
    `java.text.ParseException`
    `FTPException`
    `java.io.IOException`

### downloadByteArray

    public byte[] downloadByteArray(java.lang.String remoteFileName)
                             throws FTPException,
                                    java.io.IOException

  Download a file from the FTP server into a byte array.

  Specified by:
    `downloadByteArray` in interface `FileTransferClientInterface`
  Parameters:
    `remoteFileName` - name of the remote file to be downloaded
  Throws:
    `FTPException`
    `java.io.IOException`

### downloadFile

    public void downloadFile(java.lang.String localFileName,
                             java.lang.String remoteFileName)
                      throws FTPException,
                             java.io.IOException

  Download a file from the FTP server .

  Specified by:
    `downloadFile` in interface `FileTransferClientInterface`
  Parameters:
    `localFileName` - name (or full path) of the local file to be downloaded to
    `remoteFileName` - name of the remote file to be downloaded
  Throws:
    `FTPException`
    `java.io.IOException`

### downloadFile

    public void downloadFile(java.lang.String localFileName,
                             java.lang.String remoteFileName,
                             WriteMode writeMode)
                      throws FTPException,
                             java.io.IOException

  Download a file from the FTP server .

  Specified by:
    `downloadFile` in interface `FileTransferClientInterface`
  Parameters:
    `localFileName` - name (or full path) of the local file to be downloaded to
    `remoteFileName` - name of the remote file to be downloaded
    `writeMode` - mode in which the file is written to the client machine
  Throws:
    `FTPException`
    `java.io.IOException`

### downloadStream

    public FileTransferInputStream downloadStream(java.lang.String remoteFileName)
                                           throws FTPException,
                                                  java.io.IOException

  Download a file from the FTP server as a stream. The close() method must be called on the stream once the stream has been read.

  Specified by:
    `downloadStream` in interface `FileTransferClientInterface`
  Parameters:
    `remoteFileName` - name of the remote file to be downloaded
  Returns:
    InputStream
  Throws:
    `FTPException`
    `java.io.IOException`

### uploadFile

    public java.lang.String uploadFile(java.lang.String localFileName,
                                       java.lang.String remoteFileName)
                                throws FTPException,
                                       java.io.IOException

  Upload a file to the FTP server. If a null is supplied as the remoteFileName, the STOU (store unique) FTP feature will be used (if available) and the FTP server will generate a unique name for the file.

  Specified by:
    `uploadFile` in interface `FileTransferClientInterface`
  Parameters:
    `localFileName` - name (or full path) of the local file to be downloaded to
    `remoteFileName` - name of the remote file to be downloaded (or null to generate a unique name)
  Returns:
    name of remote file
  Throws:
    `FTPException`
    `java.io.IOException`

### uploadFile

    public java.lang.String uploadFile(java.lang.String localFileName,
                                       java.lang.String remoteFileName,
                                       WriteMode writeMode)
                                throws FTPException,
                                       java.io.IOException

  Upload a file to the FTP server. If a null is supplied as the remoteFileName, the STOU (store unique) FTP feature will be used (if available) and the FTP server will generate a unique name for the file.

  Specified by:
    `uploadFile` in interface `FileTransferClientInterface`
  Parameters:
    `localFileName` - name (or full path) of the local file to be downloaded to
    `remoteFileName` - name of the remote file to be downloaded (or null to generate a unique name)
    `writeMode` - mode to write to the remote file with
  Returns:
    name of remote file
  Throws:
    `FTPException`
    `java.io.IOException`

### uploadStream

    public FileTransferOutputStream uploadStream(java.lang.String remoteFileName)
                                          throws FTPException,
                                                 java.io.IOException

  Upload a file to the FTP server by writing to a stream. The close() method must be called on the stream once the stream has been read. If a null is supplied as the remoteFileName, the STOU (store unique) FTP feature will be used (if available) and the FTP server will generate a unique name for the file. This name can be obtained afterwards from `FileTransferOutputStream.getRemoteFile()`

  Specified by:
    `uploadStream` in interface `FileTransferClientInterface`
  Parameters:
    `remoteFileName` - name of the remote file to be uploaded
  Returns:
    FTPOutputStream
  Throws:
    `FTPException`
    `java.io.IOException`

### uploadStream

    public FileTransferOutputStream uploadStream(java.lang.String remoteFileName,
                                                 WriteMode writeMode)
                                          throws FTPException,
                                                 java.io.IOException

  Upload a file to the FTP server by writing to a stream. The close() method *must* be called on the stream once the stream has been read. If a null is supplied as the remoteFileName, the STOU (store unique) FTP feature will be used (if available) and the FTP server will generate a unique name for the file. This name can be obtained afterwards from `FileTransferOutputStream.getRemoteFile()`

  Specified by:
    `uploadStream` in interface `FileTransferClientInterface`
  Parameters:
    `remoteFileName` - name of the remote file to be uploaded
    `writeMode` - mode for writing to the server (supporting use of append)
  Returns:
    FTPOutputStream
  Throws:
    `FTPException`
    `java.io.IOException`

### getSize

    public long getSize(java.lang.String remoteFileName)
                 throws FTPException,
                        java.io.IOException

  Get the size of a remote file.

  Specified by:
    `getSize` in interface `FileTransferClientInterface`
  Parameters:
    `remoteFileName` - name of remote file
  Returns:
    long
  Throws:
    `FTPException`
    `java.io.IOException`

### getModifiedTime

    public java.util.Date getModifiedTime(java.lang.String remoteFileName)
                                   throws FTPException,
                                          java.io.IOException

  Get the modified-time of a remote file.

  Specified by:
    `getModifiedTime` in interface `FileTransferClientInterface`
  Parameters:
    `remoteFileName` - name of remote file
  Returns:
    Date
  Throws:
    `FTPException`
    `java.io.IOException`

### exists

    public boolean exists(java.lang.String remoteFileName)
                   throws FTPException,
                          java.io.IOException

  Determine if a remote file exists.

  Specified by:
    `exists` in interface `FileTransferClientInterface`
  Parameters:
    `remoteFileName` - name of remote file
  Throws:
    `FTPException`
    `java.io.IOException`

### deleteFile

    public void deleteFile(java.lang.String remoteFileName)
                    throws FTPException,
                           java.io.IOException

  Deletes a remote file.

  Specified by:
    `deleteFile` in interface `FileTransferClientInterface`
  Parameters:
    `remoteFileName` - name of remote file
  Throws:
    `FTPException`
    `java.io.IOException`

### rename

    public void rename(java.lang.String renameFromName,
                       java.lang.String renameToName)
                throws FTPException,
                       java.io.IOException

  Rename a remote file or directory.

  Specified by:
    `rename` in interface `FileTransferClientInterface`
  Parameters:
    `renameFromName` - original name
    `renameToName` - new name
  Throws:
    `FTPException,` - IOException
    `FTPException`
    `java.io.IOException`

### changeDirectory

    public void changeDirectory(java.lang.String directoryName)
                         throws FTPException,
                                java.io.IOException

  Change directory on the FTP server.

  Specified by:
    `changeDirectory` in interface `FileTransferClientInterface`
  Parameters:
    `directoryName` - name the remote directory to change into
  Throws:
    `FTPException,` - IOException
    `FTPException`
    `java.io.IOException`

### changeToParentDirectory

    public void changeToParentDirectory()
                                 throws FTPException,
                                        java.io.IOException

  Change to parent directory on the FTP server.

  Specified by:
    `changeToParentDirectory` in interface `FileTransferClientInterface`
  Throws:
    `FTPException,` - IOException
    `FTPException`
    `java.io.IOException`

### getRemoteDirectory

    public java.lang.String getRemoteDirectory()
                                        throws java.io.IOException,
                                               FTPException

  Get the current remote directory.

  Specified by:
    `getRemoteDirectory` in interface `FileTransferClientInterface`
  Returns:
    current remote directory
  Throws:
    `FTPException`
    `java.io.IOException`

### createDirectory

    public void createDirectory(java.lang.String directoryName)
                         throws FTPException,
                                java.io.IOException

  Create directory on the FTP server.

  Specified by:
    `createDirectory` in interface `FileTransferClientInterface`
  Parameters:
    `directoryName` - name the remote directory to create
  Throws:
    `FTPException,` - IOException
    `FTPException`
    `java.io.IOException`

### deleteDirectory

    public void deleteDirectory(java.lang.String directoryName)
                         throws FTPException,
                                java.io.IOException

  Create directory on the FTP server. The directory must be empty. Note that edtFTPj/PRO supports recursive directory deletions.

  Specified by:
    `deleteDirectory` in interface `FileTransferClientInterface`
  Parameters:
    `directoryName` - name the remote directory to create
  Throws:
    `FTPException,` - IOException
    `FTPException`
    `java.io.IOException`

### disconnect

    public void disconnect()
                    throws FTPException,
                           java.io.IOException

  Disconnect from the FTP server.

  Specified by:
    `disconnect` in interface `FileTransferClientInterface`
  Throws:
    `FTPException,` - IOException
    `FTPException`
    `java.io.IOException`

### disconnect

    public void disconnect(boolean immediate)
                    throws FTPException,
                           java.io.IOException

  Disconnect from the FTP server.

  Specified by:
    `disconnect` in interface `FileTransferClientInterface`
  Throws:
    `FTPException,` - IOException
    `FTPException`
    `java.io.IOException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (c) 2001-2007 Enterprise Distributed Technologies Ltd. All Rights Reserved.