Support wildcards in instance-to-host transfers - #5096
Open
onatozmenn wants to merge 3 commits into
Open
Conversation
Expand quoted instance-to-host wildcard patterns through SFTP directory listings without invoking a remote shell. Reuse the existing multi-source transfer path and require directory targets when a pattern yields multiple files. Add unit, CLI, and documentation coverage for canonical#3885.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds guest-to-host wildcard expansion for multipass transfer by expanding *, ?, and [] patterns via SFTP directory listings (no remote shell), and wires this into the CLI path while documenting the quoting requirements.
Changes:
- Implement
SFTPClient::expand_remote_path()to expand remote wildcard components usingsftp_opendir/sftp_readdir, with hidden-file filtering and sorted/deduped results. - Update
transferCLI flow to expand remote sources before pulling and to require a directory destination when expansion yields multiple matches. - Add unit + CLI tests and update CLI documentation to describe quoted wildcard usage.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_sftp_client.cpp | Adds unit tests for remote wildcard expansion behavior and error cases. |
| tests/unit/test_cli_client.cpp | Adds CLI-level unit coverage to ensure remote wildcard expansion is invoked and validated. |
| tests/unit/mock_sftp_client.h | Extends SFTP client mock to support expand_remote_path(). |
| tests/cli/cli_transfer_test.py | Adds an integration-style CLI test for transferring multiple guest files via wildcard. |
| src/ssh/sftp_client.cpp | Implements wildcard expansion using SFTP directory iteration, hidden-file rules, and deterministic ordering. |
| src/client/cli/cmd/transfer.cpp | Expands instance sources via expand_remote_path() before pull and validates directory targets for multi-match cases. |
| include/multipass/ssh/sftp_client.h | Exposes the new expand_remote_path() API on SFTPClient. |
| docs/reference/command-line-interface/transfer.md | Documents quoting remote wildcard patterns and directory-destination requirements for multi-match transfers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+72
to
+77
| sftp_dir get_dummy_sftp_dir(const fs::path& name) | ||
| { | ||
| auto dir = static_cast<sftp_dir_struct*>(calloc(1, sizeof(struct sftp_dir_struct))); | ||
| dir->name = strdup(name.string().c_str()); | ||
| return dir; | ||
| } |
Author
There was a problem hiding this comment.
Fixed in 1624a92. sftp_closedir is now mocked, and the fixture frees both the dummy handle and its name. I also recompiled the mock and SFTP test translation units with Clang 19.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When the source is inside an instance, the host shell cannot expand its path. This makes commands like this work:
Multipass expands the pattern through SFTP and then uses the existing pull path. It does not run a shell in the guest.
*,?, and character ranges are supported; hidden files still need an explicit leading dot. If a pattern matches more than one entry, the destination must be a directory.Related Issue(s)
Closes #3885
Testing
clang-format-diff-19,py_compile, andgit diff --checkpass.Screenshots (if applicable)
Not applicable.
Checklist
Additional Notes
I left the last box unchecked on purpose. I'm a person and I read and tested everything here myself, but GitHub Copilot assisted with the implementation and the tests, so ticking a line that says otherwise didn't feel right. Flagging it rather than quietly checking it, in case that changes how you want to review this.