net.sf.xbus.technical.ftp
Class FTPConnection

java.lang.Object
  extended by net.sf.xbus.technical.ftp.FTPConnection

public class FTPConnection
extends java.lang.Object

FTPConnection manages connections to FTP servers and provide methods for read and write access of files via FTP.


Method Summary
 void close()
          Closes the connection to the FTP server
 void delete(java.lang.String workDir, java.lang.String fileName)
          Deletes a file on the FTP server.
 boolean existsFile(java.lang.String workDir, java.lang.String fileName)
          Checks if a file exists on the FTP server.
static java.lang.String getFileName(java.lang.String name)
          Extracts the name of the file itself from a complete file name.
 java.lang.String getFTPName(java.lang.String workDir, java.lang.String fileName)
          Returns a string containing host, port, working directory and name of the file, mainly used for tracing.
static FTPConnection getInstance(java.lang.String name)
          Delivers an open instance of FTPConnection.
static java.lang.String getWorkingDirectory(java.lang.String name)
          Extracts the name of the directory from a complete file name.
 void rename(java.lang.String workDir, java.lang.String fromFile, java.lang.String toFile)
          Renames a file on the FTP server.
 java.lang.String retrieveFile(java.lang.String workDir, java.lang.String fileName, java.lang.String encoding)
          Retrieves the content of a file from the FTP server.
 void storeFile(java.lang.String data, java.lang.String workDir, java.lang.String fileName, java.lang.String encoding)
          Writes the given data to a file on the FTP server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static FTPConnection getInstance(java.lang.String name)
                                 throws XException
Delivers an open instance of FTPConnection.

If it is the first call with this name for the actual thread, a new FTPConnection object will be created. Subsequent calls in this thread will deliver the object, that has been created by the first call.

Parameters:
name - name of the FTPConnection
Returns:
an open FTPConnection
Throws:
XException - if something goes wrong

close

public void close()
Closes the connection to the FTP server


retrieveFile

public java.lang.String retrieveFile(java.lang.String workDir,
                                     java.lang.String fileName,
                                     java.lang.String encoding)
                              throws XException
Retrieves the content of a file from the FTP server.

Parameters:
workDir - working directory where the file is stored, may be null
fileName - name of the file without any directory information
encoding - encoding of the file
Returns:
content of the file
Throws:
XException - if something goes wrong, e.g. the file doesn't exist

storeFile

public void storeFile(java.lang.String data,
                      java.lang.String workDir,
                      java.lang.String fileName,
                      java.lang.String encoding)
               throws XException
Writes the given data to a file on the FTP server. Existing files will be overwritten.

Parameters:
data - new content of the file on the server
workDir - working directory where the file shall be stored, may be null
fileName - name of the file without any directory information
encoding - encoding of the file
Throws:
XException - if something goes wrong, e.g. the working directory doesn't exist

rename

public void rename(java.lang.String workDir,
                   java.lang.String fromFile,
                   java.lang.String toFile)
            throws XException
Renames a file on the FTP server.

Parameters:
workDir - working directory, may be null
fromFile - old name of the file, without any directory information
toFile - new name of the file, without any directory information
Throws:
XException - if something goes wrong, e.g. the fromFile doesn't exist

delete

public void delete(java.lang.String workDir,
                   java.lang.String fileName)
            throws XException
Deletes a file on the FTP server.

Parameters:
workDir - working directory, may be null
fileName - name of the file that shall be deleted, without any directory information
Throws:
XException - if something goes wrong, e.g. the file doesn't exist

existsFile

public boolean existsFile(java.lang.String workDir,
                          java.lang.String fileName)
                   throws XException
Checks if a file exists on the FTP server.

Parameters:
workDir - working directory, may be null
fileName - name of the file, without any directory information
Returns:
true if the file exists, false if not
Throws:
XException - if something goes wrong

getFTPName

public java.lang.String getFTPName(java.lang.String workDir,
                                   java.lang.String fileName)
Returns a string containing host, port, working directory and name of the file, mainly used for tracing.

Parameters:
workDir - working directory, may be null
fileName - name of the file, without any directory information
Returns:
string as described above

getWorkingDirectory

public static java.lang.String getWorkingDirectory(java.lang.String name)
Extracts the name of the directory from a complete file name.

Parameters:
name - complete name of a file, containing directory and file name
Returns:
name of the directory with leading slash, null if the name doesn't contain any directory information

getFileName

public static java.lang.String getFileName(java.lang.String name)
                                    throws XException
Extracts the name of the file itself from a complete file name.

Parameters:
name - complete name of a file, containing directory and file name
Returns:
name of the file itself
Throws:
XException - if the name of the file can't be extracted, e.g. the given name ends with a slash