org.jboss.soa.esb.util
Class FtpClientUtil

java.lang.Object
  extended by org.jboss.soa.esb.util.FtpClientUtil

public class FtpClientUtil
extends java.lang.Object

Simplified FTP transfers

Description: Implements a simple set of FTP functionality Parameters to establish the FTP connection are provided at construction time and cannot change during the lifetime of the object
Hides low level details. Current implementation is based on the "Entreprise Distributed Technology edtFTPj" library but this can be changed with no impact to existing code, just by changing this class without modifying the signature of it's public methods


Nested Class Summary
static class FtpClientUtil.XFER_TYPE
           
 
Field Summary
static java.lang.String PARMS_ASCII
           
static java.lang.String PARMS_FTP_SERVER
           
static java.lang.String PARMS_LOCAL_DIR
           
static java.lang.String PARMS_PASSIVE
           
static java.lang.String PARMS_PASSWD
           
static java.lang.String PARMS_PORT
           
static java.lang.String PARMS_REMOTE_DIR
           
static java.lang.String PARMS_USER
           
 
Constructor Summary
FtpClientUtil(ConfigTree p_oP, boolean p_bConnect)
          Checks validity and completeness of parameters, and keeps the info internally for subsequent FTP requests
FtpClientUtil(java.util.List<KeyValuePair> attribs, boolean connect)
           
 
Method Summary
 void deleteRemoteFile(java.lang.String p_sFile)
          Deletes specified file in remote directory
 void downloadFile(java.lang.String p_sFile, java.lang.String p_sFinalName)
          Downloads specified file from remote directory (remoteDirURI) to local directory (localDirURI)
static java.lang.String fileToFtpString(java.io.File p_oF)
           
 java.lang.String[] getFileListFromRemoteDir(java.lang.String p_sSuffix)
          Gets the list of files in the remote directory that end with arg0
 java.lang.String getRemoteDir()
           
 void quit()
          Terminates ftp session and frees resources Well behaved programs should make sure to call this method
 void remoteDelete(java.io.File p_oFile)
           
 void remoteRename(java.io.File p_oFrom, java.io.File p_oTo)
           
 void renameInRemoteDir(java.lang.String p_sFrom, java.lang.String p_sTo)
          Renames specified file in remote directory to specified new name
 void setRemoteDir(java.lang.String p_sDir)
          Change remote directory
 void uploadFile(java.io.File p_oFile, java.lang.String p_sRemoteName)
          Uploads specified file from local directory (localDirURI) to remote directory (remoteDirURI)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARMS_FTP_SERVER

public static final java.lang.String PARMS_FTP_SERVER
See Also:
Constant Field Values

PARMS_USER

public static final java.lang.String PARMS_USER
See Also:
Constant Field Values

PARMS_PASSWD

public static final java.lang.String PARMS_PASSWD
See Also:
Constant Field Values

PARMS_PORT

public static final java.lang.String PARMS_PORT
See Also:
Constant Field Values

PARMS_REMOTE_DIR

public static final java.lang.String PARMS_REMOTE_DIR
See Also:
Constant Field Values

PARMS_LOCAL_DIR

public static final java.lang.String PARMS_LOCAL_DIR
See Also:
Constant Field Values

PARMS_ASCII

public static final java.lang.String PARMS_ASCII
See Also:
Constant Field Values

PARMS_PASSIVE

public static final java.lang.String PARMS_PASSIVE
See Also:
Constant Field Values
Constructor Detail

FtpClientUtil

public FtpClientUtil(ConfigTree p_oP,
                     boolean p_bConnect)
              throws RemoteFileSystemException,
                     ConfigurationException
Checks validity and completeness of parameters, and keeps the info internally for subsequent FTP requests

Parameters:
p_oP - ConfigTree
Throws:
ConfigurationException - : if parameters are invalid or incomplete
  • Parameters: (XML attributes at the root level)
  • ftpServer = name or IP of FTP server
  • ftpUser = login ID for server
  • ftpPassword
  • localDirURI = absolute path in the local filesystem
  • remoteDirURI = remote path is relative to ftp user home in remote computer
  • RemoteFileSystemException

    FtpClientUtil

    public FtpClientUtil(java.util.List<KeyValuePair> attribs,
                         boolean connect)
                  throws RemoteFileSystemException,
                         ConfigurationException
    Throws:
    RemoteFileSystemException
    ConfigurationException
    Method Detail

    getRemoteDir

    public java.lang.String getRemoteDir()

    quit

    public void quit()
    Terminates ftp session and frees resources
  • Well behaved programs should make sure to call this method

  • deleteRemoteFile

    public void deleteRemoteFile(java.lang.String p_sFile)
                          throws RemoteFileSystemException
    Deletes specified file in remote directory

    Parameters:
    p_sFile - String : filename to delete. Method will attempt to delete file with rightmost node of argument within remote directory specified in 'remoteDirURI'
    Throws:
    RemoteFileSystemException - : if ftp connection cannot be established, or file cannot be deleted in remote directory

    remoteDelete

    public void remoteDelete(java.io.File p_oFile)
                      throws RemoteFileSystemException
    Throws:
    RemoteFileSystemException

    getFileListFromRemoteDir

    public java.lang.String[] getFileListFromRemoteDir(java.lang.String p_sSuffix)
                                                throws RemoteFileSystemException
    Gets the list of files in the remote directory that end with arg0

    Parameters:
    p_sSuffix - String : retrieve only files that end with that suffix - all files if null
    Throws:
    RemoteFileSystemException - : if ftp connection cannot be established, or problems encountered

    setRemoteDir

    public void setRemoteDir(java.lang.String p_sDir)
                      throws RemoteFileSystemException
    Change remote directory

    Parameters:
    p_sDir - String : directory to set
    Throws:
    RemoteFileSystemException - : if ftp connection cannot be established, or problems encountered

    renameInRemoteDir

    public void renameInRemoteDir(java.lang.String p_sFrom,
                                  java.lang.String p_sTo)
                           throws RemoteFileSystemException
    Renames specified file in remote directory to specified new name

    Parameters:
    p_sFrom - String : filename to rename
    p_sTo - String : new filename
    Throws:
    RemoteFileSystemException - : if ftp connection cannot be established, or file cannot be renamed to new name in remote directory
  • Method will attempt to rename file with rightmost node of argument within remote directory specified in 'remoteDirURI', to new name inside the SAME remote directory

  • remoteRename

    public void remoteRename(java.io.File p_oFrom,
                             java.io.File p_oTo)
                      throws RemoteFileSystemException
    Throws:
    RemoteFileSystemException

    uploadFile

    public void uploadFile(java.io.File p_oFile,
                           java.lang.String p_sRemoteName)
                    throws RemoteFileSystemException
    Uploads specified file from local directory (localDirURI) to remote directory (remoteDirURI)

    Parameters:
    p_sFile - String : filename to upload
    Throws:
    RemoteFileSystemException - : if ftp connection cannot be established, or file cannot be uploaded
  • local file will be renamed during transfer ('.xferNotReady' appended to name)
  • upon successful completion. the suffix '.xferDone' will be appended to the original filename

  • downloadFile

    public void downloadFile(java.lang.String p_sFile,
                             java.lang.String p_sFinalName)
                      throws RemoteFileSystemException
    Downloads specified file from remote directory (remoteDirURI) to local directory (localDirURI)

    Parameters:
    p_sFile - String : filename to download
    Throws:
    RemoteFileSystemException - : if ftp connection cannot be established, or file cannot be downloaded
  • local file is assigned a temporary name during transfer
  • upon successful completion, local temporary file will be renamed to name specified in argument, and suffix '.xferDone' will be appended to the original filename in the remote directory

  • fileToFtpString

    public static java.lang.String fileToFtpString(java.io.File p_oF)