smitsjelle opened a new issue, #690:
URL: https://github.com/apache/mina-sshd/issues/690

   ### Version
   
   2.14.0
   
   ### Bug description
   
   I'm using Spring Integration to write files to an SFTP server. I noticed 
that on one specific server I get odd behavior. Instead of adding the contents 
to the existing file, it overrides the content. It seems to be inserting the 
data from position `0` until it is done. If there was already more data in the 
file, that data remains. 
   
   For example, if I have a `test.txt` on my server with content `abcdefghi` 
and I send `123456` with setting APPEND, the resulting file content is 
`123456ghi` instead of `abcdefghi123456`. 
   
   In order to do the append, Spring Integrations' 
[SFTPSession#append(..)](https://github.com/spring-projects/spring-integration/blob/be8c1e281e551af4645e3f7ce654474936985f11/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/session/SftpSession.java#L144)
 method uses [AbstractSftpClient#write(String path, int bufferSize, 
Collection<OpenMode> 
mode)](https://github.com/apache/mina-sshd/blob/463c51bdc9cc8b124cb966b114a438ed255ee1de/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/impl/AbstractSftpClient.java#L1241)
 to do appends. When I change Spring's method to use the 
[SftpClient#write(Handle handle, long fileOffset, byte[] 
src)](https://github.com/apache/mina-sshd/blob/463c51bdc9cc8b124cb966b114a438ed255ee1de/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/SftpClient.java#L681C18-L681C67)
 instead, where I pass the current length of the file as its offset (retrieved 
by calling `sftpClient.stat(destination).getSize()`), the append works as 
expected. 
   
   It feels like the write method of `AbstractSftpClient` doesn't handle the 
append correctly if the supplied `OpenMode`s are `Write, Append, Create`. Is 
this correct, or is there something wrong with the parameters that are passed?  
   
   ### Actual behavior
   
   The data gets inserted from position 0 instead of getting added after the 
last position in the document. I.e.: when the inserted data is less than the 
length of the existing document, it gets overriden until the new data ends, and 
remains the same after that. 
   
   ### Expected behavior
   
   When the `OpenMode` 'Append' is provided, data is always added at the end of 
the file. 
   
   ### Relevant log output
   
   ```Shell
   
   ```
   
   ### Other information
   
   The 'getVersion' command for the server I'm encountering the issue for 
returns version 3. In testcases where I cannot reproduce the issue, the version 
is 6. Unfortunately, I don't have any further details on the configuration of 
the SFTP server I'm encountering the issue on. 


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to