davsclaus opened a new pull request, #29848:
URL: https://github.com/apache/camel/pull/29848

   _Claude Code on behalf of Claus Ibsen (davsclaus)_
   
   ## Summary
   
   [CAMEL-26925](https://issues.apache.org/jira/browse/CAMEL-26925)
   
   The `sftp` component (`SftpOperations` in camel-ftp) passed remote paths as 
they are to the JSch `ChannelSftp` methods that take a path. JSch reads `*` and 
`?` in such a path as wildcards and `\` as an escape character, so a remote 
file or directory name that contains one of these characters was matched 
against the names in the directory instead of being used as is. Storing, 
retrieving, deleting, renaming, changing the mode of, listing or changing to a 
directory could then resolve the name to another file or directory whose name 
matched, or fail when more than one name matched. The rest of Camel (the file 
and ftp components, camel-mina-sftp) uses names literally.
   
   ## Change
   
   - `SftpOperations` passes the path through the existing `quotePathForJsch` 
at each `ChannelSftp` call that interprets it: `put` (store and append, and 
`storeFileDirectly`), `get` (both retrieve modes), `rm`, `rename` (both names), 
`chmod` (file and directory), `cd`, and `ls` (the listings, the directory check 
of `buildDirectory` and the directory listing of the existence check). Before, 
only `lstat` and `readlink` were escaped.
   - `mkdir` is left as it is, as JSch sends its path without interpreting it.
   - The escaping happens at the `ChannelSftp` call only, so names, headers and 
log messages in Camel are unchanged.
   - Upgrade guide (4.24): names are now used as given; a wildcard in 
`fileName` with `useList=false`, or in the `CamelFileName` header, no longer 
selects files, and the `include`/`antInclude` options of a listing consumer do 
that instead. The entries for 4.22.3 and 4.18.6 follow with the backports.
   
   ## Tests
   
   New `SftpFileNameWithSpecialCharactersIT` (embedded SFTP server of 
camel-test-infra-ftp, 13 cases):
   
   - `storeFileWithWildcardInName`: a name with `?` or `*` is stored under that 
name, and another file whose name matches keeps its content (stepwise on and 
off).
   - `storeFileInDirectoryWithWildcardName`: a `CamelFileName` whose directory 
part is `.?` or `.*` is stored in a directory with that name under the endpoint 
directory, with the default options.
   - `tempPrefixWithBackslashInDirectoryNameWhenServerDoesNotAnswerLstat`: with 
`tempPrefix`, when the existence check of the target falls back to a directory 
listing, a directory part with backslashes is looked up and replaced literally, 
and other files keep their content.
   - `chmodOnlyChangesStoredFile`: `chmod` changes the mode of the stored file 
only.
   - `consumeAndDeleteFileWithWildcardInName`: the consumer retrieves and 
deletes the file with the given name only, with `download` on and off and 
stepwise on and off.
   
   All 13 cases fail without the change in `SftpOperations` and pass with it. 
`mvn verify` in `components/camel-ftp`: 190 tests and 489 integration tests 
pass.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to