Skip to content

GH-11121: Fix SftpSession.listNames() for root directory wildcard paths#11124

Closed
yangadam wants to merge 1 commit into
spring-projects:6.5.xfrom
yangadam:GH-11121-6.5.x
Closed

GH-11121: Fix SftpSession.listNames() for root directory wildcard paths#11124
yangadam wants to merge 1 commit into
spring-projects:6.5.xfrom
yangadam:GH-11121-6.5.x

Conversation

@yangadam

@yangadam yangadam commented Jun 16, 2026

Copy link
Copy Markdown

Summary

SftpSession.listNames("/*") throws SftpException: SSH_FX_NO_SUCH_FILE when listing files in the root directory using a wildcard pattern.

In SftpSession.doList(), the path parsing uses lastIndexOf('/') to split the directory and file parts. For root-level paths like /*, lastIndexOf('/') returns 0, but the condition checks lastIndex > 0, which excludes index 0. This means the path is never split — remoteDir stays as /* and remoteFile stays null, causing the SFTP client to try to open /* as a literal directory name.

Bug introduced in 6.0.0.

Changes

  • Changed lastIndex > 0 to lastIndex >= 0 in SftpSession.doList() so root directory paths are correctly parsed
  • Added test lsRootWildcard() that reproduces the issue and verifies the fix

Fixes: gh-11121

…ry wildcard paths

Change `lastIndex > 0` to `lastIndex >= 0` in `SftpSession.doList()` so
that root-level paths like `/*` are correctly split into directory and
file components. Previously, `lastIndexOf('/')` returning `0` was not
handled, causing the entire path to be treated as a directory name.

Fixes: spring-projectsgh-11121

Signed-off-by: Adam Yang <yangmm.adam@gmail.com>
@yangadam

Copy link
Copy Markdown
Author

@artembilan can you help review this change?

@artembilan

Copy link
Copy Markdown
Member

Closing in favor of: #11122

I said on issue that the fix might be requested against main.
We do backward cherry-picks to all supported branches.

@artembilan artembilan closed this Jun 16, 2026
@yangadam yangadam deleted the GH-11121-6.5.x branch June 17, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants