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

   # Description
   
   [CAMEL-26657](https://issues.apache.org/jira/browse/CAMEL-26657): with the 
default `stepwise=true` and `autoCreate=true`, camel-ftp and camel-sftp changed 
into the directory of every file one segment at a time and back again, and 
checked that the directory exists before every upload. For an upload into a 
two-segment directory that is 15 SFTP requests (JSch checks each `cd` with 
REALPATH and STAT) and 10 FTP commands.
   
   **What changes**
   
   - **Stepwise:** an upload, a download or (ftp) a delete stays in the 
directory of its file, so the next file in that directory needs no change of 
directory. Every operation that uses names relative to the starting directory 
changes back first: rename, listing, existence check, read lock check, site 
command, directory changes, an upload or download into another directory, and 
`FtpOperations.getClient()`. The calls made inside an upload (the existence 
check, the move of an existing file) use names relative to the file's 
directory, so they do not change back. SFTP changes back with one `cd` to the 
absolute starting directory. FTP asks for the current directory only when it 
does not know it, instead of a `PWD` per file.
   - **autoCreate:** the producer does not check a directory again before an 
upload into a directory where it already stored a file on the same connection; 
the cache is cleared on connect and disconnect. When such a directory is 
removed while the connection is open, the upload fails, the producer checks 
that the directory is really missing (SFTP `stat`, FTP `CWD`), creates it again 
and uploads once more, logged at INFO. It does not try again for a body that 
cannot be read again (stream, reader) or with `fileExist=Append`. The moves of 
a consumer (`move`, `preMove`, `moveFailed`) still check their directory each 
time.
   - **NOOP:** the ftp producer skips the `NOOP` before an upload when the 
server completed an upload, a download or a `NOOP` less than a second before 
(new default method `RemoteFileOperations.isRecentlyUsed()`, `false` unless 
overridden, so SFTP and camel-mina-sftp are unchanged). The consumer and the 
producer health check still always send it.
   
   Result per upload into the same two-segment directory with defaults: 3 SFTP 
requests (OPEN, WRITE, CLOSE) instead of 15, and on FTP no `PWD`, `CWD`, `CDUP` 
or `MKD`. The absolute paths the SFTP server sees do not change. The FTP 
command sequence does, so there is an entry in the 4.24 upgrade guide, and the 
stepwise transcript on the FTP component page is updated.
   
   **Commits**
   
   1. The change itself.
   2. Fixes from a review of the first commit: a read lock (`readLock=changed`) 
that missed every file after the first in a poll, a possible second upload when 
a status came from the chmod after a successful SFTP upload, no retry for 
reader bodies, the cache limited to uploads so consumer moves are unaffected, 
the first failure kept as suppressed, and more tests.
   
   **Tests**
   
   - New `FtpStepwiseCommandsIT` and `SftpStepwiseRequestsIT`: the commands and 
requests counted on the embedded servers for repeated uploads; a directory 
removed between uploads is created again (the retry is counted); no retry for a 
reader body or for a refused upload into an existing directory; uploads into 
other directories and without a path; a change of directory that fails half 
way; a consumer move into a removed directory; `readLock=changed` with two 
files in one poll; names relative to the starting directory after a stepwise 
upload.
   - `RemoteFileProducerPreWriteCheckTest`: the NOOP skip and the health check, 
as unit tests instead of a timing assertion.
   - `FtpConsumerSendNoopFalseIT` now detects a poll by its `LIST`, as the poll 
no longer sends `PWD`.
   - The readLock, reader-body and consumer-move tests were checked to fail 
without their fix.
   - Not covered by a test, as the embedded servers cannot produce them easily: 
an SFTP status from the chmod after a successful upload, and an FTP `SITE 
CHMOD` reply that differs from the `STOR` reply on a removed directory.
   
   Full module builds with tests: camel-ftp-common, camel-ftp (288 unit tests, 
545 integration tests) and camel-mina-sftp (shares camel-ftp-common), all 
passing.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
     Not from the root folder: built camel-ftp-common, camel-ftp and 
camel-mina-sftp with tests, ran `mvn formatter:format impsort:sort` on the 
changed modules, and committed the catalog copy of `ftp-component.adoc`.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   _Claude Code on behalf of Adriano Machado (@ammachado)_
   
   _This was generated by an AI agent and may contain inaccuracies. Please 
verify before relying on it._
   


-- 
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