Class FtpOutboundGateway

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ComponentSourceAware, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class FtpOutboundGateway extends AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
Outbound Gateway for performing remote file operations via FTP/FTPS.
Since:
2.1
Author:
Gary Russell, Artem Bilan
  • Constructor Details

    • FtpOutboundGateway

      public FtpOutboundGateway(SessionFactory<org.apache.commons.net.ftp.FTPFile> sessionFactory, MessageSessionCallback<org.apache.commons.net.ftp.FTPFile,?> messageSessionCallback)
      Construct an instance using the provided session factory and callback for performing operations on the session.
      Parameters:
      sessionFactory - the session factory.
      messageSessionCallback - the callback.
    • FtpOutboundGateway

      public FtpOutboundGateway(RemoteFileTemplate<org.apache.commons.net.ftp.FTPFile> remoteFileTemplate, MessageSessionCallback<org.apache.commons.net.ftp.FTPFile,?> messageSessionCallback)
      Construct an instance with the supplied remote file template and callback for performing operations on the session.
      Parameters:
      remoteFileTemplate - the remote file template.
      messageSessionCallback - the callback.
    • FtpOutboundGateway

      public FtpOutboundGateway(SessionFactory<org.apache.commons.net.ftp.FTPFile> sessionFactory, String command, @Nullable String expression)
      Construct an instance with the supplied session factory, a command ('ls', 'get' etc.), and an expression to determine the remote path.
      Parameters:
      sessionFactory - the session factory.
      command - the command.
      expression - the remote path expression.
    • FtpOutboundGateway

      public FtpOutboundGateway(RemoteFileTemplate<org.apache.commons.net.ftp.FTPFile> remoteFileTemplate, String command, @Nullable String expression)
      Construct an instance with the supplied remote file template, a command ('ls', 'get' etc.), and an expression to determine the remote path.
      Parameters:
      remoteFileTemplate - the remote file template.
      command - the command.
      expression - the remote path expression.
    • FtpOutboundGateway

      public FtpOutboundGateway(SessionFactory<org.apache.commons.net.ftp.FTPFile> sessionFactory, String command)
      Construct an instance with the supplied session factory and command ('ls', 'nlst', 'put' or 'mput').

      The remoteDirectory expression is null assuming to use the workingDirectory from the FTP Client.

      Parameters:
      sessionFactory - the session factory.
      command - the command.
      Since:
      4.3
    • FtpOutboundGateway

      public FtpOutboundGateway(RemoteFileTemplate<org.apache.commons.net.ftp.FTPFile> remoteFileTemplate, String command)
      Construct an instance with the supplied remote file template and command ('ls', 'nlst', 'put' or 'mput').

      The remoteDirectory expression is null assuming to use the workingDirectory from the FTP Client.

      Parameters:
      remoteFileTemplate - the remote file template.
      command - the command.
      Since:
      4.3
  • Method Details

    • setWorkingDirExpression

      public void setWorkingDirExpression(Expression workingDirExpression)
      Specify an Expression to evaluate FTP client working directory against request message.
      Parameters:
      workingDirExpression - the expression to evaluate working directory
      Since:
      5.0
    • setWorkingDirExpressionString

      public void setWorkingDirExpressionString(String workingDirExpression)
      Specify a SpEL Expression to evaluate FTP client working directory against request message.
      Parameters:
      workingDirExpression - the SpEL expression to evaluate working directory
      Since:
      5.0
    • getComponentType

      public String getComponentType()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this method to provide component type information.
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class MessageHandlerSupport
    • isDirectory

      protected boolean isDirectory(org.apache.commons.net.ftp.FTPFile file)
      Specified by:
      isDirectory in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
    • isLink

      protected boolean isLink(org.apache.commons.net.ftp.FTPFile file)
      Specified by:
      isLink in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
    • getFilename

      protected String getFilename(org.apache.commons.net.ftp.FTPFile file)
      Specified by:
      getFilename in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
    • getFilename

      protected String getFilename(AbstractFileInfo<org.apache.commons.net.ftp.FTPFile> file)
      Specified by:
      getFilename in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
    • getModified

      protected long getModified(org.apache.commons.net.ftp.FTPFile file)
      Specified by:
      getModified in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
    • asFileInfoList

      protected List<AbstractFileInfo<org.apache.commons.net.ftp.FTPFile>> asFileInfoList(Collection<org.apache.commons.net.ftp.FTPFile> files)
      Specified by:
      asFileInfoList in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
    • doInit

      protected void doInit()
      Overrides:
      doInit in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
    • enhanceNameWithSubDirectory

      protected org.apache.commons.net.ftp.FTPFile enhanceNameWithSubDirectory(org.apache.commons.net.ftp.FTPFile file, String directory)
      Specified by:
      enhanceNameWithSubDirectory in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
    • ls

      protected List<?> ls(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, String dir) throws IOException
      Description copied from class: AbstractRemoteFileOutboundGateway
      List remote files to local representation. The message can be consulted for some context for the current request; isn't used in the default implementation.
      Overrides:
      ls in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
      Parameters:
      message - the message related to the list request
      session - the session to perform list command
      dir - the remote directory to list content
      Returns:
      the list of remote files
      Throws:
      IOException - the IO exception during performing remote command
    • nlst

      protected List<String> nlst(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, String dir) throws IOException
      Description copied from class: AbstractRemoteFileOutboundGateway
      List remote files names for the provided directory. The message can be consulted for some context related to the current request; isn't used in the default implementation.
      Overrides:
      nlst in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
      Parameters:
      message - the message related to the current request
      session - the session to perform list file names command
      dir - the remote directory to list file names
      Returns:
      the list of file/directory names in the provided dir
      Throws:
      IOException - the IO exception during performing remote command
    • get

      protected File get(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, String remoteDir, String remoteFilePath, String remoteFilename, org.apache.commons.net.ftp.FTPFile fileInfoParam) throws IOException
      Description copied from class: AbstractRemoteFileOutboundGateway
      Copy a remote file to the configured local directory.
      Overrides:
      get in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
      Parameters:
      message - the message.
      session - the session.
      remoteDir - the remote directory.
      remoteFilePath - the remote file path.
      remoteFilename - the remote file name.
      fileInfoParam - the remote file info; if null we will execute an 'ls' command first.
      Returns:
      The file.
      Throws:
      IOException - Any IOException.
    • mGet

      protected List<File> mGet(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, String remoteDirectory, String remoteFilename) throws IOException
      Overrides:
      mGet in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
      Throws:
      IOException
    • rm

      protected boolean rm(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, String remoteFilePath) throws IOException
      Description copied from class: AbstractRemoteFileOutboundGateway
      Perform remote delete for the provided path. The message can be consulted to determine some context; isn't used in the default implementation.
      Overrides:
      rm in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
      Parameters:
      message - the request message related to the path to remove
      session - the remote protocol session to perform remove command
      remoteFilePath - the remote path to remove
      Returns:
      true or false as a result of the remote removal
      Throws:
      IOException - the IO exception during performing remote command
    • mv

      protected boolean mv(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, String remoteFilePath, String remoteFileNewPath) throws IOException
      Description copied from class: AbstractRemoteFileOutboundGateway
      Move one remote path to another. The message can be consulted to determine some context; isn't used in the default implementation.
      Overrides:
      mv in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
      Parameters:
      message - the request message related to this move command
      session - the remote protocol session to perform move command
      remoteFilePath - the source remote path
      remoteFileNewPath - the target remote path
      Returns:
      true or false as a result of the operation
      Throws:
      IOException - the IO exception during performing remote command
    • put

      protected String put(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, String subDirectory)
      Description copied from class: AbstractRemoteFileOutboundGateway
      Put the file based on the message to the remote server. The message can be consulted to determine some context. The session argument isn't used in the default implementation.
      Overrides:
      put in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
      Parameters:
      message - the request message related to this put command
      session - the remote protocol session related to this invocation context
      subDirectory - the target sub-directory to put
      Returns:
      The remote path, or null if no local file was found.
    • mPut

      protected List<String> mPut(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, File localDir)
      Description copied from class: AbstractRemoteFileOutboundGateway
      Put files from the provided directory to the remote server recursively. The message can be consulted to determine some context. The session argument isn't used in the default implementation.
      Overrides:
      mPut in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
      Parameters:
      message - the request message related to this mPut command
      session - the remote protocol session for this invocation context
      localDir - the local directory to mput to the server
      Returns:
      The list of remote paths for sent files
    • isChmodCapable

      public boolean isChmodCapable()
      Overrides:
      isChmodCapable in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
    • doChmod

      protected void doChmod(RemoteFileOperations<org.apache.commons.net.ftp.FTPFile> remoteFileOperations, String path, int chmod)
      Description copied from class: AbstractRemoteFileOutboundGateway
      Set the mode on the remote file after transfer; the default implementation does nothing.
      Overrides:
      doChmod in class AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
      Parameters:
      remoteFileOperations - the remote file template.
      path - the path.
      chmod - the chmod to set.