Class FileTransferConnection

All Implemented Interfaces:
AdaptrisComponent, AdaptrisConnection, ComponentLifecycle, ComponentLifecycleExtension, StateManagedComponent
Direct Known Subclasses:
FileTransferConnectionUsingPassword, StandardSftpConnection

public abstract class FileTransferConnection extends NoOpConnection
Class containing common configuration for all FTP Connection types.
  • Field Details

  • Constructor Details

    • FileTransferConnection

      public FileTransferConnection()
  • Method Details

    • setForceRelativePath

      public void setForceRelativePath(Boolean b)
      Force the path to be relative when using getDirectoryRoot(String).

      This is useful in the situation where the server in question does not have the user in a ftp jail

      Parameters:
      b - true to prefix a . to the path.
      See Also:
    • getForceRelativePath

      public Boolean getForceRelativePath()
      Get the force relative path flag.
      Returns:
      true or false.
      See Also:
    • forceRelativePath

      public boolean forceRelativePath()
    • getDefaultUserName

      public String getDefaultUserName()

      Returns the default user name.

      Returns:
      the default user name
    • setDefaultUserName

      public void setDefaultUserName(String s)
      Set the user name.
      Parameters:
      s - the username.
    • getDefaultControlPort

      public Integer getDefaultControlPort()
      Returns:
      Returns the defaultControlPort.
    • defaultControlPort

      public abstract int defaultControlPort()
    • setDefaultControlPort

      public void setDefaultControlPort(Integer i)
      Override the default port.
      Parameters:
      i - The defaultControlPort to set.
    • setAdditionalDebug

      public void setAdditionalDebug(Boolean b)
      Get additional logging output where available.
      Parameters:
      b - true to get additional logging.
    • getAdditionalDebug

      public Boolean getAdditionalDebug()
      The additional debug flag.
      Returns:
      true or false (default false)
      See Also:
    • additionalDebug

      public boolean additionalDebug()
    • getWindowsWorkAround

      public Boolean getWindowsWorkAround()
      Returns:
      the windowsWorkAround
      See Also:
    • setWindowsWorkAround

      public void setWindowsWorkAround(Boolean b)
      Set whether the target server is a windows machine that returns backslash separated filenames when doing NLIST on a directory rather than the normal forward slashes.
      Parameters:
      b - the windowsWorkAround to set
    • windowsWorkaround

      public boolean windowsWorkaround()
    • getCacheConnection

      public Boolean getCacheConnection()
      Returns:
      whether connection is held open after use
    • setCacheConnection

      public void setCacheConnection(Boolean b)
      Set whether or not connections created are held open for future use.

      This feature is primarily intended to mitigate the connection cost when using FtpConsumer with a frequent poll interval.If multiple components end up using the same FileTransferClient instance from the cache (perhaps you have multiple FtpConsumer instances configured in the same channel) then you will likely end up with non-optimal performance due to thread synchronisation.

      It is generally recommended that you configure the associated FtpConsumer and FtpProducer instances using the URL form of the destination if you intend to use the caching feature; this allows you to make sure that each component has its own unique FileTransferClient instance associated with it.

      Parameters:
      b - true to enable, default false.
      See Also:
    • cacheConnection

      public boolean cacheConnection()
    • initConnection

      protected void initConnection() throws CoreException
      Description copied from class: AdaptrisConnectionImp
      Initialise the underlying connection.
      Overrides:
      initConnection in class NoOpConnection
      Throws:
      CoreException - wrapping any exception.
      See Also:
    • closeConnection

      protected void closeConnection()
      Description copied from class: AdaptrisConnectionImp
      Close the underlying connection.
      Overrides:
      closeConnection in class NoOpConnection
      See Also:
    • connect

      Connect to the host.
      Parameters:
      hostUrl - the host to connect to which can be in the form of an url or simply just the hostname in which case the default credentials and port numbers are used.
      Returns:
      an FtpClient that is ready to use.
      Throws:
      FileTransferException
      IOException
      PasswordException
    • getMaxClientCacheSize

      public Integer getMaxClientCacheSize()
      Get the max number of entries in the cache.
      Returns:
      the maximum number of entries.
    • setMaxClientCache

      public void setMaxClientCache(Integer maxSize)
      Set the max number of entries in the cache.

      Entries will be removed on a least recently accessed basis.

      Parameters:
      maxSize - the maximum number of entries, default is 16
      See Also:
    • maxClientCacheSize

      public int maxClientCacheSize()
    • getCacheExpiration

      public TimeInterval getCacheExpiration()
    • setCacheExpiration

      public void setCacheExpiration(TimeInterval expiration)
    • withCacheExpiration

      public <T extends FileTransferConnection> T withCacheExpiration(TimeInterval i)
    • expirationMillis

      protected long expirationMillis()
    • acceptProtocol

      protected abstract boolean acceptProtocol(String s)
      Validate the URL Protocol when a URL is used.
      Parameters:
      s - the URL Protocol
      Returns:
      true if the URL protocol is acceptable to the concrete imp.
    • create

      Create an instance of the FileTransferClient for use with the producer or consumer.
      Parameters:
      host - the remote host.
      port - the port to connect to
      ui - a local UserInfo containing username and password
      Returns:
      a FileTransferClient object
      Throws:
      IOException - wrapping a general comms error.
      FileTransferException - if a protocol specific exception occurred.
      PasswordException
    • getDirectoryRoot

      public String getDirectoryRoot(String hostUrl)

      Returns the directory root for the passed host URL.

      Parameters:
      hostUrl - the host URL
      Returns:
      the directory root for the passed host URL
    • disconnect

      public void disconnect(FileTransferClient ftp)
      Disconnect the FTP client.
      Parameters:
      ftp - the ftp client implementation
    • createUserInfo

      protected abstract FileTransferConnection.UserInfo createUserInfo() throws FileTransferException
      Throws:
      FileTransferException