org.shept.util
Class FtpFileCopy

java.lang.Object
  extended by org.shept.util.FtpFileCopy

public class FtpFileCopy
extends Object

Version:
$$Id: FtpFileCopy.java 34 2010-08-20 16:46:49Z aha $$
Author:
Andi

Field Summary
private static org.apache.commons.logging.Log logger
           
 
Constructor Summary
FtpFileCopy()
           
 
Method Summary
protected  boolean acceptFile(org.apache.commons.net.ftp.FTPFile file, String pattern)
           
private  boolean configSetup(FtpConfig config, org.apache.commons.net.ftp.FTPClient ftpC)
           
private  boolean ensureFtpDirectory(org.apache.commons.net.ftp.FTPClient ftpClient, String basePath, String path)
          Creates the needed directories if necessary.
 SortedMap<FileNameDate,org.apache.commons.net.ftp.FTPFile> fileMapByNameAndDate(org.apache.commons.net.ftp.FTPClient ftp, String filePattern)
          List the file directory as specified by the name filter and the path directory The maps keys contain name and modification date for comparison
 int ftpSyncLocal(FtpConfig config, String localPath, String filePattern)
           
 int ftpSyncRemote(FtpConfig config, String remotePath, String filePattern)
           
 Integer syncPull(org.apache.commons.net.ftp.FTPClient ftpSource, String localDestPat, String filePattern)
          Compare the source path and the destination path for filenames with the filePattern e.g.
 Integer syncPush(String localSourcePath, org.apache.commons.net.ftp.FTPClient ftpDest, String filePattern)
          Compare the source path and the destination path for filenames with the filePattern e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final org.apache.commons.logging.Log logger
Constructor Detail

FtpFileCopy

public FtpFileCopy()
Method Detail

configSetup

private boolean configSetup(FtpConfig config,
                            org.apache.commons.net.ftp.FTPClient ftpC)
                     throws IOException
Parameters:
-
config -
ftpC -
Returns:
Throws:
SocketException
IOException

ftpSyncLocal

public int ftpSyncLocal(FtpConfig config,
                        String localPath,
                        String filePattern)

ftpSyncRemote

public int ftpSyncRemote(FtpConfig config,
                         String remotePath,
                         String filePattern)

syncPull

public Integer syncPull(org.apache.commons.net.ftp.FTPClient ftpSource,
                        String localDestPat,
                        String filePattern)
                 throws IOException
Compare the source path and the destination path for filenames with the filePattern e.g. *.bak, *tmp and copy these files to the destination dir if they are not present at the destination or if they have changed (by modifactionDate). Copying is done through a retrieve operation.

Parameters:
ftpSource -
localDestPat -
filePattern -
Returns:
the number of files being copied
Throws:
IOException

syncPush

public Integer syncPush(String localSourcePath,
                        org.apache.commons.net.ftp.FTPClient ftpDest,
                        String filePattern)
                 throws IOException
Compare the source path and the destination path for filenames with the filePattern e.g. *.bak, *tmp and copy these files to the destination dir if they are not present at the destination or if they have changed (by modifactionDate). Copying is done from local directory into remote ftp destination directory.

Parameters:
destPath -
localSourcePath -
filePattern -
Returns:
the number of files being copied
Throws:
IOException

fileMapByNameAndDate

public SortedMap<FileNameDate,org.apache.commons.net.ftp.FTPFile> fileMapByNameAndDate(org.apache.commons.net.ftp.FTPClient ftp,
                                                                                       String filePattern)
                                                                                throws IOException
List the file directory as specified by the name filter and the path directory The maps keys contain name and modification date for comparison

Throws:
IOException

acceptFile

protected boolean acceptFile(org.apache.commons.net.ftp.FTPFile file,
                             String pattern)

ensureFtpDirectory

private boolean ensureFtpDirectory(org.apache.commons.net.ftp.FTPClient ftpClient,
                                   String basePath,
                                   String path)
                            throws IOException
Creates the needed directories if necessary.

Parameters:
ftpClient - A FTPClient being connected.
basePath - The base path. This one has to exist on the ftp server!
path - The path to be created.
Throws:
IOException - IN case of an error.


Copyright © 2011. All Rights Reserved.