Skip to content

Fix S3ToSFTPOperator and S3ToFTPOperator failing on S3 folder-marker keys - #77514

Open
rokadepiyush49-rgb wants to merge 2 commits into
apache:mainfrom
rokadepiyush49-rgb:fix/77513-s3-sftp-folder-markers
Open

rokadepiyush49-rgb wants to merge 2 commits into
apache:mainfrom
rokadepiyush49-rgb:fix/77513-s3-sftp-folder-markers

Conversation

@rokadepiyush49-rgb

@rokadepiyush49-rgb rokadepiyush49-rgb commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

closes: #77513

With s3_filenames="*", S3ToSFTPOperator and S3ToFTPOperator transfer every key that list_keys returns. Folders created in the S3 console are stored as empty objects whose key ends in /. The operators tried to store those as files at a directory path, and the server rejected them (550 Is a directory. on FTP). S3 lists keys in sorted order, so the marker of s3_key itself comes first, and the task failed before any file was moved.

Both operators now create each folder marker as a directory, with any missing parents, before any file is copied, as GCSToSFTPOperator does since #73880. An existing directory is accepted, so a rerun works. A string prefix still doesn't select markers, since they have no file name, and they no longer appear in the warning about files the prefix did not select. The s3_filenames docstring describes this.

S3ToSFTPOperator uses paramiko through SSHHook (amazon doesn't depend on the sftp provider), so it has a small mkdir -p helper. On FTP, MKD answers 550 for an existing directory, so that helper checks with CWD first. Directory paths go through validate_destination_path, like files.

Not changed: an explicit list (s3_filenames=[...]) and single-file mode, where nothing is listed. Unlike GCSToSFTPOperator's create_intermediate_dirs, the parent directory of a file that has no marker is not created, so such nested keys still need the destination subdirectory to exist; that is existing behavior, noted in the issue.

Testing

  • In both test modules: test_execute_creates_folder_markers_as_directories (missing parents created, an empty folder kept, an existing directory accepted, every directory before any file), test_execute_fails_on_folder_marker_that_cannot_be_a_directory (a file at the marker path, and a marker escaping the destination path), and a prefix case where a marker is neither selected, created nor reported.
  • test_s3_to_ftp.py and TestS3ToSFTPOperatorInit: 33 passed. The SSH-server tests in TestS3ToSFTPOperator need a local sshd and were left to CI.
  • Against real servers, pyftpdlib for FTP and asyncssh for SFTP, with moto S3 holding reports/, reports/jan.csv, reports/sub/, reports/sub/two.txt, an empty reports/empty/ and reports/deep/nested/ with no marker for deep/: every directory was created, the files landed in them, and a second run passed too.
  • prek run on the changed files: all hooks passed.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code following the guidelines

…keys

With s3_filenames="*", both operators transferred every key that
list_keys returned, including the folder markers (keys ending in "/")
that the S3 console creates for each folder. Storing such a key as a
file at a directory path fails on the server ("550 Is a directory." on
FTP), so the task failed before any real file was moved.

Skip every key ending in "/" right after listing, and log the skipped
keys. Unlike the object-store transfers fixed in apache#76408, an SFTP or FTP
server cannot hold a file whose path ends in "/", so a marker that no
other key overlaps is skipped too.

closes: apache#77513

Generated-by: Claude Code
Copilot AI balanced review requested due to automatic review settings November 23, 2026 22:32
@boring-cyborg boring-cyborg Bot added area:providers provider:amazon AWS/Amazon - related issues labels Nov 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@yuseok89 yuseok89 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one inline comment. If it's feasible, could you check whether creating the directories would work here?

Comment on lines +152 to +155
# A key ending in "/" is a folder marker, such as the S3 console creates for each
# folder. An SFTP server cannot store a file at a path ending in "/", so skip every
# marker, not only those that overlap other keys as the object-store transfers do.
folder_markers = [k for k in all_keys if k.endswith("/")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, S3ToSFTPOperator would skip every folder marker, while GCSToSFTPOperator, which writes to the same kind of destination, creates each marker as a directory by default since #73880. So the same empty folder would end up on the SFTP server or not, depending on the source bucket.

What do you think about creating the directory here too, instead of skipping it? The same could apply to S3ToFTPOperator, since FTP has directories as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good point. Since #73880 makes GCSToSFTPOperator create markers as directories, I've changed both operators to do the same with "*": each folder marker is created as a directory, with any missing parents, before any file is copied, and an existing directory is accepted, so a rerun works. A string prefix still doesn't select markers, since they have no file name.

S3ToSFTPOperator uses paramiko through SSHHook (amazon doesn't depend on the sftp provider), so it has a small mkdir -p helper. On FTP, MKD answers 550 for an existing directory, so that helper checks with CWD first. Directory paths go through validate_destination_path, like files.

I tried it against real servers (pyftpdlib and asyncssh) with reports/, reports/sub/, an empty reports/empty/ and reports/deep/nested/ with no marker for deep/: every directory was created, the files landed in them, and a second run passed too.

I didn't add a switch like create_intermediate_dirs, since markers used to fail the task, so there's no old behavior to keep. Unlike GCSToSFTPOperator, this doesn't create the parent directory of a file that has no marker; I left that out to keep the PR focused, but I can add it if you'd prefer full parity.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this into account! I ran it on my side with a real S3 bucket and local SFTP and FTP servers, and it works well.

…fers

Instead of skipping folder markers with s3_filenames="*", create each one
as a directory on the server, with any missing parents, before any file
is transferred. This matches GCSToSFTPOperator since apache#73880, so the same
empty folder reaches the server whichever bucket it comes from. An
existing directory is accepted, so a rerun works, and directory paths go
through validate_destination_path like file paths.

S3ToSFTPOperator uses paramiko through SSHHook, since the amazon provider
does not depend on the sftp provider, so it gets a small mkdir -p helper.
On FTP, MKD answers 550 for an existing directory, so the helper checks
with CWD first. A string prefix still does not select folder markers.

Generated-by: Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S3ToSFTPOperator and S3ToFTPOperator fail on S3 folder-marker keys with s3_filenames="*"

3 participants