Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFTPSession.append() not working correctly #8566

Closed
sergiodelgadocastellanos opened this issue Mar 1, 2023 · 1 comment · Fixed by #8576
Closed

SFTPSession.append() not working correctly #8566

sergiodelgadocastellanos opened this issue Mar 1, 2023 · 1 comment · Fixed by #8576

Comments

@sergiodelgadocastellanos

In what version(s) of Spring Integration are you seeing this issue?

6.0

Describe the bug

When calling the SFTPSession.append() method, the application returns a SSH_FX_NO_SUCH_FILE. I've tried with the file already created in the SFTP server, and I've tried also with the method write and then trying to append but the append method throws the same error.

I've been looking into the code and I think that a flag is missing:

@OverRide
public void append(InputStream inputStream, String destination) throws IOException {
synchronized (this.sftpClient) {
OutputStream outputStream =
this.sftpClient.write(destination, SftpClient.OpenMode.Create, SftpClient.OpenMode.Append);
FileCopyUtils.copy(inputStream, outputStream);
}
}

In the flags the SftpClient.OpenMode.Write is missing. I've tried the same exact code but with that added flag and it works that way with the intended functionality (appending to a file).

To Reproduce

Create a sample application connected to a SFTP Server and trying to use the method SFTPSession.append().

Expected behavior

The expected behavior would be for the content to be appended to a file already existing, or to create a new file with the content if such file doesn't exist.

The actual behavior is the fail I've mentioned earlier.

@sergiodelgadocastellanos sergiodelgadocastellanos added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Mar 1, 2023
@artembilan artembilan added in: sftp backport 6.0.x and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Mar 1, 2023
@artembilan artembilan added this to the 6.1.0-M2 milestone Mar 1, 2023
@artembilan
Copy link
Member

I don't think adding that SftpClient.OpenMode.Write flag would give us some issue.
Our tests with an append command against Apache MINA are passing either way.
Feel free to contribute such a simple fix: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc!

artembilan added a commit to artembilan/spring-integration that referenced this issue Mar 16, 2023
Fixes spring-projects#8566

Turns out some SFTP servers are strict enough to not let to append into existing file
if we don't give in addition a `Write` open mode flag as well

**Cherry-pick to `6.0.x`**
garyrussell pushed a commit that referenced this issue Mar 20, 2023
Fixes #8566

Turns out some SFTP servers are strict enough to not let to append into existing file
if we don't give in addition a `Write` open mode flag as well

**Cherry-pick to `6.0.x`**
garyrussell pushed a commit that referenced this issue Mar 20, 2023
Fixes #8566

Turns out some SFTP servers are strict enough to not let to append into existing file
if we don't give in addition a `Write` open mode flag as well

**Cherry-pick to `6.0.x`**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants