Class FtpOutboundGateway
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.handler.AbstractMessageProducingHandler
org.springframework.integration.handler.AbstractReplyProducingMessageHandler
org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
org.springframework.integration.ftp.gateway.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
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway
AbstractRemoteFileOutboundGateway.Command, AbstractRemoteFileOutboundGateway.Option
Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler.RequestHandler
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
messagingTemplate
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionFtpOutboundGateway
(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').FtpOutboundGateway
(RemoteFileTemplate<org.apache.commons.net.ftp.FTPFile> remoteFileTemplate, String command, String expression) Construct an instance with the supplied remote file template, a command ('ls', 'get' etc.), and an expression to determine the remote path.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.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').FtpOutboundGateway
(SessionFactory<org.apache.commons.net.ftp.FTPFile> sessionFactory, String command, String expression) Construct an instance with the supplied session factory, a command ('ls', 'get' etc.), and an expression to determine the remote path.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. -
Method Summary
Modifier and TypeMethodDescriptionprotected List<AbstractFileInfo<org.apache.commons.net.ftp.FTPFile>>
asFileInfoList
(Collection<org.apache.commons.net.ftp.FTPFile> files) protected void
doChmod
(RemoteFileOperations<org.apache.commons.net.ftp.FTPFile> remoteFileOperations, String path, int chmod) Set the mode on the remote file after transfer; the default implementation does nothing.protected void
doInit()
protected org.apache.commons.net.ftp.FTPFile
enhanceNameWithSubDirectory
(org.apache.commons.net.ftp.FTPFile file, String directory) 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) Copy a remote file to the configured local directory.Subclasses may implement this method to provide component type information.protected String
getFilename
(org.apache.commons.net.ftp.FTPFile file) protected String
getFilename
(AbstractFileInfo<org.apache.commons.net.ftp.FTPFile> file) protected long
getModified
(org.apache.commons.net.ftp.FTPFile file) boolean
protected boolean
isDirectory
(org.apache.commons.net.ftp.FTPFile file) protected boolean
isLink
(org.apache.commons.net.ftp.FTPFile file) protected List<?>
List remote files to local representation.mGet
(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, String remoteDirectory, String remoteFilename) Put files from the provided directory to the remote server recursively.protected boolean
mv
(Message<?> message, Session<org.apache.commons.net.ftp.FTPFile> session, String remoteFilePath, String remoteFileNewPath) Move one remote path to another.List remote files names for the provided directory.protected String
Put the file based on the message to the remote server.protected boolean
Perform remote delete for the provided path.void
setWorkingDirExpression
(Expression workingDirExpression) Specify anExpression
to evaluate FTP client working directory against request message.void
setWorkingDirExpressionString
(String workingDirExpression) Specify a SpELExpression
to evaluate FTP client working directory against request message.Methods inherited from class org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway
assertRemoteFileTemplateMutability, filterFile, filterFiles, filterMputFiles, getFullFileName, getRemoteFilename, getRemoteFileTemplate, handleRequestMessage, purgeDots, purgeLinks, remoteFileTemplateExplicitlySet, setAutoCreateDirectory, setAutoCreateLocalDirectory, setCharset, setChmod, setChmodOctal, setFileExistsMode, setFileNameExpression, setFileNameGenerator, setFilter, setLocalDirectory, setLocalDirectoryExpression, setLocalDirectoryExpressionString, setLocalFilenameGeneratorExpression, setLocalFilenameGeneratorExpressionString, setMputFilter, setOption, setOptions, setRemoteDirectoryExpression, setRemoteFileSeparator, setRenameExpression, setRenameExpressionString, setTemporaryFileSuffix, setTemporaryRemoteDirectoryExpression, setUseTemporaryFileName
Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
doInvokeAdvisedRequestHandler, getBeanClassLoader, getIntegrationPatternType, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReply
Methods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, setupMessageProcessor, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeaders
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention
Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface reactor.core.CoreSubscriber
currentContext
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
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 isnull
assuming to use theworkingDirectory
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 isnull
assuming to use theworkingDirectory
from the FTP Client.- Parameters:
remoteFileTemplate
- the remote file template.command
- the command.- Since:
- 4.3
-
-
Method Details
-
setWorkingDirExpression
Specify anExpression
to evaluate FTP client working directory against request message.- Parameters:
workingDirExpression
- the expression to evaluate working directory- Since:
- 5.0
-
setWorkingDirExpressionString
Specify a SpELExpression
to evaluate FTP client working directory against request message.- Parameters:
workingDirExpression
- the SpEL expression to evaluate working directory- Since:
- 5.0
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classMessageHandlerSupport
-
isDirectory
protected boolean isDirectory(org.apache.commons.net.ftp.FTPFile file) - Specified by:
isDirectory
in classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
-
isLink
protected boolean isLink(org.apache.commons.net.ftp.FTPFile file) - Specified by:
isLink
in classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
-
getFilename
- Specified by:
getFilename
in classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
-
getFilename
- Specified by:
getFilename
in classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
-
getModified
protected long getModified(org.apache.commons.net.ftp.FTPFile file) - Specified by:
getModified
in classAbstractRemoteFileOutboundGateway<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 classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
-
doInit
protected void doInit()- Overrides:
doInit
in classAbstractRemoteFileOutboundGateway<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 classAbstractRemoteFileOutboundGateway<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 classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
- Parameters:
message
- the message related to the list requestsession
- the session to perform list commanddir
- 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 classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
- Parameters:
message
- the message related to the current requestsession
- the session to perform list file names commanddir
- 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 classAbstractRemoteFileOutboundGateway<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 classAbstractRemoteFileOutboundGateway<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 classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
- Parameters:
message
- the request message related to the path to removesession
- the remote protocol session to perform remove commandremoteFilePath
- 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 classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
- Parameters:
message
- the request message related to this move commandsession
- the remote protocol session to perform move commandremoteFilePath
- the source remote pathremoteFileNewPath
- 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 classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
- Parameters:
message
- the request message related to this put commandsession
- the remote protocol session related to this invocation contextsubDirectory
- 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 classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
- Parameters:
message
- the request message related to this mPut commandsession
- the remote protocol session for this invocation contextlocalDir
- the local directory to mput to the server- Returns:
- The list of remote paths for sent files
-
isChmodCapable
public boolean isChmodCapable()- Overrides:
isChmodCapable
in classAbstractRemoteFileOutboundGateway<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 classAbstractRemoteFileOutboundGateway<org.apache.commons.net.ftp.FTPFile>
- Parameters:
remoteFileOperations
- the remote file template.path
- the path.chmod
- the chmod to set.
-