Holger's
Java API

com.antelmann.net
Class FTPConnector

java.lang.Object
  extended by com.antelmann.net.FTPConnector
All Implemented Interfaces:
ThirdParty

public class FTPConnector
extends Object
implements ThirdParty

FTPConnector implements some useful methods for an FTP client. The methods are synchronized as they use an exclusive connection to the host for performing the operations.

This class uses the package package org.apache.commons.net.ftp, which is available at http://jakarta.apache.org/commons/net/index.html.

Alternatively, you may also use the package com.oroinc.net.ftp from the Java NetComponents Library by Original Reusable Objects, which is available at this location. The license for that package is unfortunately NOT GNU, see here for details.

Since:
11/08/02
Author:
Holger Antelmann

Constructor Summary
FTPConnector(String host, String user, String passwd)
           
 
Method Summary
 void downloadFile(String remoteDir, String remoteFileName, File targetFile)
          downloads a single file from the given FTP site to the specified target file.
 Object[] downloadTree(String remoteSourceDir, File targetDir)
          recursively downloads the remoteSourceDir tree to the targetDir.
 Object[] downloadTree(String remoteSourceDir, File targetDir, Logger logger)
          uses a Logger to provide feedback.
 Object[] downloadTree(String remoteSourceDir, File targetDir, Logger logger, Monitor monitor)
          uses a Monitor for enabling to cancel the operation prematurely.
 Object[] synchronizeDirectory(File sourceDir, String remoteTargetDir, boolean deleteRemoteFiles)
          synchronizes the sourceDir with the remoteTargetDir on the FTP host recursively.
 Object[] synchronizeDirectory(File sourceDir, String remoteTargetDir, boolean deleteRemoteFiles, Logger logger)
          This method allows for intermediate feedback through the logger; otherwise it's the same as the other synchronizeDirectory() method.
 Object[] synchronizeDirectory(File sourceDir, String remoteTargetDir, boolean deleteRemoteFiles, Logger logger, Monitor monitor)
          This method allows for intermediate feedback and interactive stopping; otherwise it's the same as the other synchronizeDirectory() method.
 void uploadFile(File sourceFile, String targetDir, String targetFileName)
          uploads a single local file to the given FTP site using the specified targetDir and targetFileName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FTPConnector

public FTPConnector(String host,
                    String user,
                    String passwd)
Method Detail

uploadFile

public void uploadFile(File sourceFile,
                       String targetDir,
                       String targetFileName)
                throws IOException
uploads a single local file to the given FTP site using the specified targetDir and targetFileName. This method establishes and closes one connection per call.

Throws:
IOException

downloadFile

public void downloadFile(String remoteDir,
                         String remoteFileName,
                         File targetFile)
                  throws IOException
downloads a single file from the given FTP site to the specified target file. This method establishes and closes one connection per call. An alternative to download a file from an FTP server is to use the class Downloader.

Throws:
IOException
See Also:
Downloader

downloadTree

public Object[] downloadTree(String remoteSourceDir,
                             File targetDir)
                      throws IOException
recursively downloads the remoteSourceDir tree to the targetDir. Existing files will be overwritten. Dots or slashes at the beginning of the remoteSourceDir will be ignored. A new FTP connection is opened to perform the operation and closed at the end if the method returns normally.

Returns:
array of objects that could not be copied; if no errors occurred, this array would be empty
Throws:
IOException

downloadTree

public Object[] downloadTree(String remoteSourceDir,
                             File targetDir,
                             Logger logger)
                      throws IOException
uses a Logger to provide feedback.

Returns:
array of objects that could not be copied; if no errors occurred, this array would be empty
Throws:
IOException
See Also:
(String, targetDir)

downloadTree

public Object[] downloadTree(String remoteSourceDir,
                             File targetDir,
                             Logger logger,
                             Monitor monitor)
                      throws IOException
uses a Monitor for enabling to cancel the operation prematurely. The monitor is tested after each logger operation.

Returns:
array of objects that could not be copied; if no errors occurred, this array would be empty
Throws:
IOException
See Also:
(String, targetDir, logger)

synchronizeDirectory

public Object[] synchronizeDirectory(File sourceDir,
                                     String remoteTargetDir,
                                     boolean deleteRemoteFiles)
                              throws IOException
synchronizes the sourceDir with the remoteTargetDir on the FTP host recursively. Dots or slashes at the beginning of the remoteTargetDir will be ignored. A new FTP connection is opened to perform the operation and closed at the end if the method returns normally. The procedure follows the follwing rules: Note that file attributes are ignored, i.e. if a file is copied, the default attributes are kept and may be different from those of the originating file. If a directory is to be removed in the destination dir, the method makes a best effort to do so.

Returns:
array of objects that could not be copied or deleted; if no errors occurred, this array would be empty
Throws:
IllegalArgumentException - if the sourceDir is not a directory
IOException

synchronizeDirectory

public Object[] synchronizeDirectory(File sourceDir,
                                     String remoteTargetDir,
                                     boolean deleteRemoteFiles,
                                     Logger logger)
                              throws IOException
This method allows for intermediate feedback through the logger; otherwise it's the same as the other synchronizeDirectory() method.

This method allows e.g. GUIs to display status messages by implementing a special LogWriter.
The given logger may be null, otherwise its usage is as follows:

Returns:
array of objects that could not be copied or deleted; if no errors occurred, this array would be empty
Throws:
IOException
See Also:
synchronizeDirectory(File, String, boolean)

synchronizeDirectory

public Object[] synchronizeDirectory(File sourceDir,
                                     String remoteTargetDir,
                                     boolean deleteRemoteFiles,
                                     Logger logger,
                                     Monitor monitor)
                              throws IOException
This method allows for intermediate feedback and interactive stopping; otherwise it's the same as the other synchronizeDirectory() method.

This method allows monitoring threads to abort the synchronization by disabling the given monitor during processing. The monitor/logger may be null; monitor checks occur for each directory and after each copy operation.

Returns:
array of objects that could not be copied or deleted; if no errors occurred, this array would be empty
Throws:
IOException
See Also:
synchronizeDirectory(File, String, boolean, Logger)


(c) 2001-2006 Holger Antelmann - all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads