REFACTOR: Align sftp task path handling with the file task#70
Conversation
The sftp task now writes to as it is given, dropping the directory
auto-append and the isDirLike/cache helpers, so it matches the file
write task. To reuse the source file's name, template the path, e.g.
{{ context CATERPILLAR_FILE_NAME_WRITE }}. Unnessary comments are dropped.
BREAKING: is renamed to , and a directory destination
no longer auto-appends the source filename - use explicit templating.
Align download globbing with the file task: a glob path is now matched with doublestar (so and work) by walking the static base directory, instead of pkg/sftp's single-level path.Match. A bare directory is no longer auto-expanded — use a glob (e.g. or ) to read its files. No new dependency — doublestar is already used by the file task.
There was a problem hiding this comment.
Pull request overview
This PR refactors the sftp pipeline task to align its path semantics and glob behavior with the existing file task: it renames remote_path → path, removes implicit filename appending on upload, and upgrades download globbing to support doublestar patterns (**, {a,b}).
Changes:
- Rename SFTP config field from
remote_pathtopathacross code + docs + example pipelines. - Upload (sink) now treats
pathas an explicit per-record destination (no directory auto-append of upstream filename). - Download (source) now matches globs using
doublestar.Matchby walking and matching remote paths, enabling**recursion and brace expansion.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/pipelines/sftp/upload.yaml | Updates example upload pipeline to use path and explicitly template CATERPILLAR_FILE_NAME_WRITE. |
| test/pipelines/sftp/s3_to_sftp.yaml | Updates S3→SFTP example to use path and explicit filename templating. |
| test/pipelines/sftp/download.yaml | Updates example download pipeline to use path for globbing. |
| README.md | Updates supported-task description to reflect SFTP’s supported modes (upload/download). |
| internal/pkg/pipeline/task/sftp/sftp.go | Renames config field to Path and updates comments accordingly. |
| internal/pkg/pipeline/task/sftp/README.md | Documents new path behavior and doublestar glob support; updates examples. |
| internal/pkg/pipeline/task/sftp/operations.go | Implements new upload semantics and switches download globbing to doublestar matching over walked remote paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var matches []string | ||
| walker := client.Walk(globBase(remotePath)) | ||
| for walker.Step() { | ||
| if err := walker.Err(); err != nil { | ||
| return nil, fmt.Errorf(`walking %q: %w`, remotePath, err) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Divyanshu Tiwari (divyanshu-tiwari)
left a comment
There was a problem hiding this comment.
please explore doublestar v4, it has some function which I think can be used here.
Some points regarding doublestarv4:
|
5ad2d27 to
d36a965
Compare
| func (s *sftp) download(client *pkgsftp.Client, output chan<- *record.Record) error { | ||
|
|
||
| remotePath, err := s.RemotePath.Get(nil) | ||
| remotePath, err := s.Path.Get(nil) |
There was a problem hiding this comment.
| remotePath, err := s.Path.Get(nil) | |
| path, err := s.Path.Get(nil) |
Description
Follow-up to the SFTP task PR, aligning the
sftptask a little more with the existingfiletask after feedback by Divyanshu Tiwari (@divyanshu-tiwari)
Changes:
The tables below show what each role supports, and what changed
Field rename
remote_pathpathUpload (sink) —
pathbehaviorpathis a full file path (/out/x.csv)pathis a directory (/out/){{ context "CATERPILLAR_FILE_NAME_WRITE" }}Download (source) —
pathpatterns/out/a.csv/out/*.csv,?,[…]path.Match)doublestar.Match)**/out/**/*.csvdoublestar)/out/{a,b}/*.csv{a,b}expands to alternatives (doublestar)/out//out/*)/out/gone.csv/out/*.json(base dir exists)On
doublestar: thefiletask already globs with thedoublestarlibrary -doublestar.Globin its local reader anddoublestar.Match(over the keys itlists) in its S3 reader. doublestar extends Go's standard
path.Matchwithrecursive
**(match across any number of directories) and{a,b}braceexpansion. The sftp source previously used
pkg/sftp'sGlob, which ispath.Match-based (single-level, no**or{a,b}). This PR switches it tothe same
doublestar.Match, so the sftp task now accepts the same glob syntaxas the file task.
Test:

Types of changes
Checklist