TobKed commented on a change in pull request #11284:
URL: https://github.com/apache/airflow/pull/11284#discussion_r501508699



##########
File path: airflow/providers/google/cloud/transfers/gcs_to_sftp.py
##########
@@ -129,15 +134,25 @@ def execute(self, context):
                 )
 
             prefix, delimiter = self.source_object.split(WILDCARD, 1)
+            prefix_dirname = os.path.dirname(prefix)
+
             objects = gcs_hook.list(self.source_bucket, prefix=prefix, 
delimiter=delimiter)
 
             for source_object in objects:
-                destination_path = os.path.join(self.destination_path, 
source_object)
+                if self.ignore_gcs_path_in_destination:
+                    source_object_basename = os.path.relpath(source_object, 
start=prefix_dirname)
+                    destination_path = os.path.join(self.destination_path, 
source_object_basename)
+                else:
+                    destination_path = os.path.join(self.destination_path, 
source_object)
                 self._copy_single_object(gcs_hook, sftp_hook, source_object, 
destination_path)
 
             self.log.info("Done. Uploaded '%d' files to %s", len(objects), 
self.destination_path)
         else:
-            destination_path = os.path.join(self.destination_path, 
self.source_object)
+            if self.ignore_gcs_path_in_destination:
+                source_object_basename = os.path.basename(self.source_object)
+                destination_path = os.path.join(self.destination_path, 
source_object_basename)
+            else:
+                destination_path = os.path.join(self.destination_path, 
self.source_object)

Review comment:
       Thanks @turbaszek , it is a great suggestion.
   I modified it slightly: 
https://github.com/apache/airflow/pull/11284/commits/9b9ef602a170125344c3b03c1eaca5c077719eb5

##########
File path: airflow/providers/google/cloud/transfers/gcs_to_sftp.py
##########
@@ -52,6 +52,9 @@ class GCSToSFTPOperator(BaseOperator):
     :param destination_path: The sftp remote path. This is the specified 
directory path for
         uploading to the SFTP server.
     :type destination_path: str
+    :param ignore_gcs_path_in_destination: (Optional) When set to False the 
path of the file

Review comment:
       Sure. Example was added.

##########
File path: airflow/providers/google/cloud/transfers/gcs_to_sftp.py
##########
@@ -52,6 +52,9 @@ class GCSToSFTPOperator(BaseOperator):
     :param destination_path: The sftp remote path. This is the specified 
directory path for
         uploading to the SFTP server.
     :type destination_path: str
+    :param ignore_gcs_path_in_destination: (Optional) When set to False the 
path of the file

Review comment:
       I renamed it to `keep_directory_structure`. Thanks @mik-laj !




----------------------------------------------------------------
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.

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


Reply via email to