Class FTPConnection

java.lang.Object
org.deltava.util.ftp.FTPConnection
All Implemented Interfaces:
Closeable, AutoCloseable

public class FTPConnection extends Object implements Closeable
A utility class to encapsulate FTP operations.
Since:
1.0
Version:
11.2
Author:
Luke
  • Constructor Details

    • FTPConnection

      public FTPConnection(String host)
      Creates a new FTP connection object.
      Parameters:
      host - the remote host name
  • Method Details

    • getClient

      public com.enterprisedt.net.ftp.FTPClient getClient()
      Returns the underlying FTP client object.
      Returns:
      the client object
    • isConnected

      public boolean isConnected()
      Returns if connected to the remote server.
      Returns:
      TRUE if connected to the server, otherwise FALSE
    • connect

      public void connect(String user, String pwd) throws FTPClientException
      Connects and logs into the remote server.
      Parameters:
      user - the user ID
      pwd - the password
      Throws:
      FTPClientException - if a connection error occurs
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • get

      public InputStream get(String fName, boolean saveToDisk) throws FTPClientException
      Downloads a file from the remote server.
      Parameters:
      fName - the remote file name
      saveToDisk - TRUE if the file should be saved to a temporary file, otherwise FALSE
      Returns:
      an InputStream pointing to the file data
      Throws:
      FTPClientException - if an error occurs
    • get

      public InputStream get(String fName, File destFile) throws FTPClientException
      Downloads a file from the remote server into a specified location.
      Parameters:
      fName - the remote file name
      destFile - the destination location
      Returns:
      an InputStream pointing to the file data
      Throws:
      FTPClientException - if an error occurs
    • put

      public void put(File f) throws FTPClientException
      Uploads a file to the remote server.
      Parameters:
      f - the local File
      Throws:
      FTPClientException - if an error occurs
    • hasFile

      public boolean hasFile(String dirName, String fName) throws FTPClientException
      Returns whether a particular file exists on the remote server.
      Parameters:
      dirName - the remote directory name
      fName - the remote file name
      Returns:
      TRUE if the file exists, otherwise FALSE
      Throws:
      FTPClientException - if an error occurs
    • getTimestamp

      public Instant getTimestamp(String dirName, String fName) throws FTPClientException
      Returns the last modified date for a particular file on the remote server.
      Parameters:
      dirName - the remote directory name
      fName - the remote file name
      Returns:
      the last modified date/time, or null if the file does not exist on the remote server
      Throws:
      FTPClientException - if an error occurs
    • getNewestDirectory

      public String getNewestDirectory(String dirName, FilenameFilter filter) throws FTPClientException
      Returns the name of the newest directory on the FTP server.
      Parameters:
      dirName - the directory name
      filter - a FilenameFilter, or null if none
      Returns:
      the file name, or null if not found
      Throws:
      FTPClientException - if an error occurs
    • getNewest

      public String getNewest(String dirName, FilenameFilter filter) throws FTPClientException
      Returns the name of the newest file on the FTP server.
      Parameters:
      dirName - the directory name
      filter - a FilenameFilter, or null if none
      Returns:
      the file name, or null if not found
      Throws:
      FTPClientException - if an error occurs