INT-4060: FTP Gateway: Add NLST and workDir
JIRA: https://jira.spring.io/browse/INT-4060 * Add `NLST` command to the `AbstractRemoteFileOutboundGateway` to perform `listNames` on the target session. Useful in case of server doesn't allow to perform `LS` or the names set is sufficient for application requirements * Add `workingDirExpression` to the `FtpOutboundGateway` to allow to perform `FtpClient.changeWorkingDirectory()` based on the current request message * Change `slf4j-log4j12` to the `testCompile` - the FTP tests fail in the IDE with `ClassNotFoundException` Address PR comments * Add `nlst` to XSD config * Reinstate `ls -1` test-case for the `FtpServerOutboundTests` * wrap more commands to the `doInWorkingDirectory()` Fix `MV` command in the `AbstractRemoteFileOutboundGateway` * Implement `RemoteFileOperations#invoke(OperationsCallback<F, T>)` for thread-bound `session`s * Use a new `invoke()` for `put()` and `mPut()` commands in the `AbstractRemoteFileOutboundGateway` * Add delegation for the `put()` and `mPut()` commands in the `FtpOutboundGateway` * Add DSL support for the `workingDirExpression` and add `whats-new.adoc` note Document changes Address some PR comments: * Add `invokeScope` variable to `execute` to track `ThreadLocal` session or not * Check for `null` in the `getSession()` and fallback to regular `sessionFactory.getSession()`. Most likely the `invoke()` is called from other thread Doc Polishing
This commit is contained in:
committed by
Gary Russell
parent
b7801f6311
commit
3daeaab1b4
@@ -768,6 +768,7 @@ The _FTP Outbound Gateway_ provides a limited set of commands to interact with a
|
||||
Commands supported are:
|
||||
|
||||
* ls (list files)
|
||||
* nlst (list file names)
|
||||
* get (retrieve file)
|
||||
* mget (retrieve file(s))
|
||||
* rm (remove file(s))
|
||||
@@ -804,6 +805,22 @@ From Java perspective there are two new constructor without `expression` argumen
|
||||
The `null` for `LS` command is treated as an Client working directory according to the FTP protocol.
|
||||
The working directory can be set via the `FTPClient.changeWorkingDirectory()` function when you extend the `DefaultFtpSessionFactory` and implement `postProcessClientAfterConnect()` callback.
|
||||
|
||||
*nlst*
|
||||
|
||||
(Since _version 5.0_)
|
||||
|
||||
Lists remote file names and supports the following options:
|
||||
|
||||
* -f - do not sort the list
|
||||
|
||||
The message payload resulting from an _nlst_ operation is a list of file names.
|
||||
|
||||
The remote directory that the _nlst_ command acted on is provided in the `file_remoteDirectory` header.
|
||||
|
||||
Unlike the `-1` option for the _ls_ command (see above), which uses the `LIST` command, the _nlst_ command sends an `NLST` command to the target FTP server.
|
||||
This command is useful when the server doesn't support `LIST`, due to security restrictions, for example.
|
||||
The result of the _nlst_ is just the names, therefore the framework can't determine if an entity is a directory, to perform filtering or recursive listing, for example.
|
||||
|
||||
*get*
|
||||
|
||||
_get_ retrieves a remote file and supports the following option:
|
||||
@@ -986,11 +1003,9 @@ Here is an example of a gateway configured for an ls command...
|
||||
reply-channel="toSplitter"/>
|
||||
----
|
||||
|
||||
The payload of the message sent to the toSplitter channel is a list of String objects containing the filename of each
|
||||
file.
|
||||
The payload of the message sent to the `toSplitter` channel is a list of String objects containing the filename of each file.
|
||||
If the `command-options` was omitted, it would be a list of `FileInfo` objects.
|
||||
Options are provided space-delimited, e.g.
|
||||
`command-options="-1 -dirs -links"`.
|
||||
Options are provided space-delimited, e.g. `command-options="-1 -dirs -links"`.
|
||||
|
||||
Starting with _version 4.2_, the `GET`, `MGET`, `PUT` and `MPUT` commands support a `FileExistsMode` property (`mode`
|
||||
when using the namespace support). This affects the behavior when the local file exists (`GET` and `MGET`) or the remote
|
||||
@@ -998,6 +1013,9 @@ file exists (`PUT` and `MPUT`). Supported modes are `REPLACE`, `APPEND`, `FAIL`
|
||||
For backwards compatibility, the default mode for `PUT` and `MPUT` operations is `REPLACE` and for `GET` and `MGET`
|
||||
operations, the default is `FAIL`.
|
||||
|
||||
Starting with _version 5.0_, the `setWorkingDirExpression()` (`working-dir-expression`) option is provided on the `FtpOutboundGateway` (`<int-ftp:outbound-gateway>`) enabling the client working directory to be changed at runtime; the expression is evaluated against the request message.
|
||||
The previous working directory is restored after each gateway operation.
|
||||
|
||||
==== Configuring with Java Configuration
|
||||
|
||||
The following Spring Boot application provides an example of configuring the Outbound Gateway using Java configuration:
|
||||
@@ -1179,6 +1197,12 @@ Since we know that the `FileExistsMode.FAIL` case is always only looking for a f
|
||||
|
||||
For any other cases the `FtpRemoteFileTemplate` can be extended for implementing a custom logic in the overridden `exist()` method.
|
||||
|
||||
Starting with _version 5.0_, the new `RemoteFileOperations.invoke(OperationsCallback<F, T> action)` method is available.
|
||||
This method allows several `RemoteFileOperations` calls to be called in the scope of the same, thread-bounded, `Session`.
|
||||
This is useful when you need to perform several high-level operations of the `RemoteFileTemplate` as one unit of work.
|
||||
For example `AbstractRemoteFileOutboundGateway` uses it with the _mput_ command implementation, where we perform a _put_ operation for each file in the provided directory and recursively for its sub-directories.
|
||||
See the JavaDocs for more information.
|
||||
|
||||
[[ftp-session-callback]]
|
||||
=== MessageSessionCallback
|
||||
|
||||
|
||||
@@ -289,6 +289,13 @@ For more information, refer to the http://docs.spring.io/spring-integration/api/
|
||||
|
||||
Additional methods were added in _version 4.1_ including `getClientInstance()` which provides access to the underlying `ChannelSftp` enabling access to low-level APIs.
|
||||
|
||||
Starting with _version 5.0_, the new `RemoteFileOperations.invoke(OperationsCallback<F, T> action)` method is available.
|
||||
This method allows several `RemoteFileOperations` calls to be called in the scope of the same, thread-bounded, `Session`.
|
||||
This is useful when you need to perform several high-level operations of the `RemoteFileTemplate` as one unit of work.
|
||||
For example `AbstractRemoteFileOutboundGateway` uses it with the _mput_ command implementation, where we perform a _put_ operation for each file in the provided directory and recursively for its sub-directories.
|
||||
See the JavaDocs for more information.
|
||||
|
||||
|
||||
[[sftp-inbound]]
|
||||
=== SFTP Inbound Channel Adapter
|
||||
|
||||
@@ -791,6 +798,7 @@ The _SFTP Outbound Gateway_ provides a limited set of commands to interact with
|
||||
Commands supported are:
|
||||
|
||||
* ls (list files)
|
||||
* nlst (list file names)
|
||||
* get (retrieve file)
|
||||
* mget (retrieve file(s))
|
||||
* rm (remove file(s))
|
||||
@@ -821,6 +829,20 @@ If the `-dirs` option is included, each recursive directory is also returned as
|
||||
In this case, it is recommended that the `-1` is not used because you would not be able to determine files Vs.
|
||||
directories, which is achievable using the `FileInfo` objects.
|
||||
|
||||
*nlst*
|
||||
|
||||
(Since _version 5.0_)
|
||||
|
||||
Lists remote file names and supports the following options:
|
||||
|
||||
* -f - do not sort the list
|
||||
|
||||
The message payload resulting from an _nlst_ operation is a list of file names.
|
||||
|
||||
The remote directory that the _nlst_ command acted on is provided in the `file_remoteDirectory` header.
|
||||
|
||||
The SFTP protocol doesn't provide _list names_ functionality, s this command is fully equivalent of the _ls_ command with `-1` option and added here for convenience.
|
||||
|
||||
*get*
|
||||
|
||||
_get_ retrieves a remote file and supports the following option:
|
||||
|
||||
@@ -136,6 +136,12 @@ The FTP and SFTP outbound channel adapters, as well as `PUT` command of the outb
|
||||
The inbound channel adapters now can build file tree locally and use a new `RecursiveDirectoryScanner` by default for local directory.
|
||||
Also these adapters can now be switched to the `WatchService` instead.
|
||||
|
||||
The `NLST` command has been added to the `AbstractRemoteFileOutboundGateway` to perform only list files names remote command.
|
||||
|
||||
The `FtpOutboundGateway` can now be supplied with `workingDirExpression` to change the FTP client working directory for the current request message.
|
||||
|
||||
The `RemoteFileTemplate` is supplied now with the `invoke(OperationsCallback<F, T> action)` to perform several `RemoteFileOperations` calls in the scope of the same, thread-bounded, `Session`.
|
||||
|
||||
See <<ftp>> and <<sftp>> for more information.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user