rokadepiyush49-rgb commented on code in PR #77514:
URL: https://github.com/apache/airflow/pull/77514#discussion_r4681949369


##########
providers/amazon/src/airflow/providers/amazon/aws/transfers/s3_to_sftp.py:
##########
@@ -149,7 +149,19 @@ def execute(self, context: Context) -> None:
             if isinstance(self.s3_filenames, str):
                 self.log.info("Getting files in s3://%s/%s", self.s3_bucket, 
self.s3_key)
                 all_keys = s3_hook.list_keys(bucket_name=self.s3_bucket, 
prefix=self.s3_key) or []
-                filenames = [k[len(self.s3_key) :] for k in all_keys]
+                # 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("/")]

Review Comment:
   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.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to