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

SftpInboundFileSynchronizer fails to synchronize files if the directory path is a symbolic link #9821

Closed
jandurovec opened this issue Feb 12, 2025 · 2 comments

Comments

@jandurovec
Copy link

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

6.4.1

Describe the bug

After upgrading from previous version (as part of Spring Boot 2.x -> SpringBoot 3.x migration) SftpInboundFileSynchronizer stopped syncing the files. We have isolated the problem to be related to a situation where the directory to synchronize is a symlink (i.e. last element in the path is a symlink).

To Reproduce

  • Create /tmp/realdir on SFTP server and place a file (eg aaa.txt there)
  • Create /tmp/link on SFTP server as a symlink pointing to /tmp/realdir
  • Configure SftpInboundFileSynchronizer to synchronize the content of /tmp/link

Expected behavior

aaa.txt is downloaded from SFTP to local filesystem

Analysis

SftpInboundFileSynchronizer (via its parent AbstractInboundFileSynchronizer) calls list() method to retrieve the directory content

The problem is that SftpSession calls lstat on a file/directory and if it is not reported as a directory (which it isn't since it's a symbolic link), it fails silently and returns empty list.

SftpClient.Attributes attributes = this.sftpClient.lstat(path);
if (!attributes.isDirectory()) {
return Stream.of(new SftpClient.DirEntry(remoteFile, path, attributes));
}

I believe that SftpSession.doList(String path) method should call stat() instead of lstat() so that it resolves also symlinks.

@jandurovec jandurovec added status: waiting-for-triage The issue need to be evaluated and its future decided type: bug labels Feb 12, 2025
@artembilan
Copy link
Member

Yeah...

I even see difference in their JavaDocs:

    /**
     * Retrieve remote path meta-data - do <B>not</B> follow symbolic links
     *
     * @param  path        The remote path
     * @return             The associated {@link Attributes}
     * @throws IOException If failed to execute
     */
    Attributes lstat(String path) throws IOException;

    /**
     * Retrieve file/directory handle meta-data
     *
     * @param  handle      The {@link Handle} obtained via one of the {@code open} calls
     * @return             The associated {@link Attributes}
     * @throws IOException If failed to execute
     */
    Attributes stat(Handle handle) throws IOException;

I just changed it to stat() in our logic and all the test for SFTP are green.

If that is what you are looking for, I'm happy to push the fix.

Thanks

@artembilan artembilan added this to the 6.5.0-M2 milestone Feb 12, 2025
@artembilan artembilan added in: sftp for: backport-to-6.3.x for: backport-to-6.4.x and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Feb 12, 2025
@jandurovec
Copy link
Author

That would be great. This is a regression issue for us and it would be great if the retrieval of symlinked dir content worked as described above (and as it worked before migration from JSch)

spring-builds pushed a commit that referenced this issue Feb 12, 2025
Fixes: #9821
Issue link: #9821

Previously, Spring Integration used JSch library for SFTP protocol,
and that one was able to follow symlinks.
Currently, the `SftpSession` uses `LSTAT` command which does not follow symlinks

* Fix `SftpSession` to call `sftpClient.stat()` instead of `lstat()`
to mitigate migration pain from JSch

(cherry picked from commit efa8dc5)
spring-builds pushed a commit that referenced this issue Feb 12, 2025
Fixes: #9821
Issue link: #9821

Previously, Spring Integration used JSch library for SFTP protocol,
and that one was able to follow symlinks.
Currently, the `SftpSession` uses `LSTAT` command which does not follow symlinks

* Fix `SftpSession` to call `sftpClient.stat()` instead of `lstat()`
to mitigate migration pain from JSch

(cherry picked from commit efa8dc5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants