Class FtpEITransport

java.lang.Object
com.nt.udc.ndk.node.EITransport
com.nt.udc.ei.transport.FtpEITransport
All Implemented Interfaces:
DataProviderIfc, DCTransport, FileDataProviderIfc, Runnable

public class FtpEITransport extends EITransport
Used to retrieve files from an FTP server. This class serves as an EI transport within the NDK framework and retrieves either a single file or multiple files within a remote path periodically. To use this class, you instantiate it with the IP address of the machine from which you want to retrieve files (known as the FTP server), the FTP username/password, and either a remote file path and file suffix combination, or the path and name of a single file. (There are two constructors available for you.) There is also a constructor parameter which indicates whether you want to use binary or ASCII transfer mode.

This class also relies on an object of type SynchronizedDirectory, which provides the synchronization capability for this transport class and any class which consumes (processes) the files that are retrieved via objects of this class.

  • Field Details

  • Constructor Details

    • FtpEITransport

      public FtpEITransport(String ip, String l, String pw, EINode node)
      This form of the constructor establishes the minimum FTP parameters for this transport. If you use this form you must manually set the required FTP parameters via the class accessors.
      Parameters:
      ip - The IP address of the FTP server
      l - The username to use for loggin in
      pw - The password for the given username
      node - The EI Node that is using this transport object
    • FtpEITransport

      public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary)
      This form of the constructor is used when you need to retrieve multiple files at a time, such as all the files ending in 'dat' in a given path on the FTP server.
      Parameters:
      ip - The IP address of the FTP server
      l - The username to use for loggin in
      pw - The password for the given username
      st - The number of milliseconds to wait between successive retrievals
      flag - Determines whether to delete the remote files once they are retrieved
      rp - The path or directory on the FTP server that contains the files
      suffix - Specifies the suffix for the files that will be retrieved
      lSuffix - Specifies the suffix for the files on the local machine after they're retrieved
      dir - The local directory into which files will be placed
      node - The EI Node that is using this transport object
      binary - Determines if files should be retrieved in binary mode (false = ASCII mode)
    • FtpEITransport

      public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, String ftpType)
      This constructor is used when the ftpType needs to be specified
      Parameters:
      ftpType - Determines the type of FTP to use
    • FtpEITransport

      public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary)
      This form of the constructor is used when you need to retrieve just a single file periodically.
      Parameters:
      ip - The IP address of the FTP server
      l - The username to use for logging in
      pw - The password for the given username
      st - The number of milliseconds to wait between successive retrievals
      flag - Determines whether to delete the remote files once they are retrieved
      file - Specifies the file that will be retrieved (including path)
      dir - The local directory into which files will be placed
      node - The EI Node that is using this transport object
      binary - Determines if files should be retrieved in binary mode (or ASCII mode)
    • FtpEITransport

      public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, String ftpType)
      This constructor is used when the ftpType needs to be specified
      Parameters:
      ftpType - Determines the type of FTP to use
    • FtpEITransport

      public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameflag)
      This form of the constructor is used when you need to retrieve multiple files at a time, such as all the files ending in 'dat' in a given path on the FTP server.
      Parameters:
      ip - The IP address of the FTP server
      l - The username to use for loggin in
      pw - The password for the given username
      st - The number of milliseconds to wait between successive retrievals
      flag - Determines whether to delete the remote files once they are retrieved
      rp - The path or directory on the FTP server that contains the files
      suffix - Specifies the suffix for the files that will be retrieved
      lSuffix - Specifies the suffix for the files on the local machine after they're retrieved
      dir - The local directory into which files will be placed
      node - The EI Node that is using this transport object
      binary - Determines if files should be retrieved in binary mode (false = ASCII mode)
      rRenameflag - flag for Renaming Remote File
    • FtpEITransport

      public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String rp, String suffix, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameflag, String ftpType)
      This constructor is used when the ftpType needs to be specified
      Parameters:
      ftpType - Determines the type of FTP to use
    • FtpEITransport

      public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameFlag)
      This form of the constructor is used when you need to retrieve just a single file periodically.
      Parameters:
      ip - The IP address of the FTP server
      l - The username to use for logging in
      pw - The password for the given username
      st - The number of milliseconds to wait between successive retrievals
      flag - Determines whether to delete the remote files once they are retrieved
      file - Specifies the file that will be retrieved (including path)
      dir - The local directory into which files will be placed
      node - The EI Node that is using this transport object
      binary - Determines if files should be retrieved in binary mode (or ASCII mode)
      rRenameFlag - flag for Renaming Remote File
    • FtpEITransport

      public FtpEITransport(String ip, String l, String pw, int st, boolean flag, String file, String lSuffix, SynchronizedDirectory dir, DCNode node, boolean binary, boolean rRenameFlag, String ftpType)
      This constructor is used when the ftpType needs to be specified
      Parameters:
      ftpType - Determines the type of FTP to use
  • Method Details

    • run

      public void run()
      Workhorse of this class: Continuously retrieve the files and process them until it's time to shut down. Note the use of the "wasInterrupted" flag to help keep track of when this thread gets interrupted. If the thread is in the middle of the connectAndGet() method, we must let it finish before shutting down the thread.
      Specified by:
      run in interface Runnable
      Specified by:
      run in class EITransport
    • connectAndGetFiles

      protected boolean connectAndGetFiles()
      This method actually creates the connection, retrieves the files and notifies the consumer of the files via the SynchronizedDirectory. This method is used whenever the instance variable remoteFile is null, which indicates we need to retrieve multiple files at a time.
      Returns:
      true, if successful - false, if not
    • connectAndGetSingleFile

      protected boolean connectAndGetSingleFile()
      This method actually creates the connection, retrieves a file and notifies the consumer of the file via the SynchronizedDirectory. This method is used whenever the instance variable remoteFile is not null, which indicates we need to retrieve just a single file.
      Returns:
      true, if successful - false, if not
    • sleep

      protected void sleep(int sleepSecs) throws InterruptedException
      Sleep for a given interval
      Throws:
      InterruptedException
    • shutdown

      public void shutdown()
      Description copied from class: EITransport
      This method is used to provide a means of shutting down the transport in an orderly fashion.
      Specified by:
      shutdown in interface DCTransport
      Specified by:
      shutdown in class EITransport
    • getRetrivalList

      protected ArrayList getRetrivalList() throws IOException
      Throws:
      IOException
    • getData

      public DCFieldContainer getData()
      Not used.
      Specified by:
      getData in interface DataProviderIfc
      Specified by:
      getData in class EITransport
      Returns:
      DCFieldContainer.
    • getBulkData

      public DCFieldContainer[] getBulkData()
      Not used.
      Specified by:
      getBulkData in interface DataProviderIfc
      Specified by:
      getBulkData in class EITransport
      Returns:
      DCFieldContainer object array, containing the data that is for processing
    • isDataAvailable

      public boolean isDataAvailable()
      Not used.
      Specified by:
      isDataAvailable in interface DataProviderIfc
      Specified by:
      isDataAvailable in class EITransport
      Returns:
      true, if data is available
    • setUseTimestampInLocalName

      public void setUseTimestampInLocalName(boolean flag)
      Sets flag that determines if timestamp is used to form part of the local file name of a retrieved file.
    • setOverwriteExisting

      public void setOverwriteExisting(boolean flag)
      Sets flag that determines if files should be overwritten via FTP.
    • setBinaryMode

      public void setBinaryMode()
      Sets the FTP retrieval mode to binary. Call this after constructing the transport, or ftpSession will be null and this method will have no effect.
    • setASCIIMode

      public void setASCIIMode()
      Sets the FTP retrieval mode to ASCII Call this after constructing the transport, or ftpSession will be null and this method will have no effect.
    • setRemotePath

      public void setRemotePath(String path)
      Sets the path from which to retrieve file(s) on the FTP server. Use this when you need to retrieve multiple files at a time.
      Parameters:
      path - remote path
    • getRemotePath

      public String getRemotePath()
      Accesses the path from which to retrieve file(s) on the FTP server.
      Returns:
      remote path
    • setLocalSuffix

      public void setLocalSuffix(String suffix)
      Sets the suffix of files that need to be processed. This determines the suffix of the files once they are retrieved via FTP.
      Parameters:
      suffix - local suffix
    • getLocalSuffix

      public String getLocalSuffix()
      Accesses the local suffix.
      Returns:
      local suffix
    • setRemoteSuffix

      public void setRemoteSuffix(String suffix)
      Sets the suffix of files to retrieve from the FTP server. Use this when you need to retrieve multiple files at a time.
      Parameters:
      suffix - remote suffix
    • getFlattenDirs

      public boolean getFlattenDirs()
    • setFlattenDirs

      public void setFlattenDirs(boolean value)
    • getRemoteSuffix

      public String getRemoteSuffix()
      Accesses the remote suffix.
      Returns:
      remote suffix
    • setSleepTime

      public void setSleepTime(int time)
      Sets the time to wait before subsequent retrievals.
      Parameters:
      time - number of seconds to wait
    • getSleepTime

      public int getSleepTime()
      Accesses the time to wait before subsequent retrievals.
      Returns:
      number of seconds to wait
    • setSynchronizedDirectory

      public void setSynchronizedDirectory(SynchronizedDirectory dir)
      Establishes the "common" local directory into which files are retrieved and from which files are processed.
      Parameters:
      dir - encapsulation of the local directory
    • getSynchronizedDirectory

      public SynchronizedDirectory getSynchronizedDirectory()
      Accesses the "common" local directory into which files are retrieved and from which files are processed.
      Returns:
      encapsulation of the local directory
    • setDeleteRemoteFiles

      public void setDeleteRemoteFiles(boolean flag)
      Sets flag for deleting remote files once retrieved.
      Parameters:
      flag - true = delete remote files
    • getDeleteRemoteFiles

      public boolean getDeleteRemoteFiles()
      Access flag for deleting remote files.
      Returns:
      true = delete remote files
    • setRemoteFile

      public void setRemoteFile(String filespec)
      Sets the name of the remote file to be retrieved. Must include the full path, if needed. Use this when you want to retrieve just a single file.
      Parameters:
      filespec - remote path and filename
    • getRemoteFile

      public String getRemoteFile()
      Accesses the name of the remote file to be retrieved.
      Returns:
      remote path and filename (can be null)
    • setRenameRemoteSuffix

      public void setRenameRemoteSuffix(boolean flag)
      Sets the flag for renaming Remote Files
      Parameters:
      flag - true will set it
    • getRenameRemoteSuffix

      public boolean getRenameRemoteSuffix()
      Gets the flag for renaming remote files
      Returns:
      true if we want to rename remote files
    • getUsername

      public String getUsername() throws NullPointerException
      Retrieves the login name for the FTP session.
      Returns:
      login name (can be null)
      Throws:
      NullPointerException - if ftpSession hasn't been established
    • getPassword

      public String getPassword() throws NullPointerException
      Retrieves the password for the FTP session.
      Returns:
      password (can be null)
      Throws:
      NullPointerException - if ftpSession hasn't been established
    • getIPAddress

      public String getIPAddress() throws NullPointerException
      Accesses the IP address of the FTP server.
      Returns:
      IP address (can be null)
      Throws:
      NullPointerException - if ftpSession hasn't been established
    • enablePassiveFTP

      public void enablePassiveFTP(boolean passive)
      Enable the use of Passive FTP.
      Parameters:
      passive - true is Passive FTP is desired.
    • getLocalName

      protected String getLocalName(String remoteFile)
    • isHealthy

      public boolean isHealthy()
      This method is used to check if the transport is fully functional.
      Specified by:
      isHealthy in interface DCTransport
      Overrides:
      isHealthy in class EITransport
      Returns:
      true if the transport is healthy, false otherwise