@@ -100,23 +100,26 @@ def __init__(
100100 self .operation = operation
101101 self .confirm = confirm
102102 self .create_intermediate_dirs = create_intermediate_dirs
103+ self .local_filepath = local_filepath
104+ self .remote_filepath = remote_filepath
103105
104- self .local_filepath_was_str = False
105- if isinstance (local_filepath , str ):
106- self .local_filepath = [local_filepath ]
107- self .local_filepath_was_str = True
106+ def execute (self , context : Any ) -> str | list [str ] | None :
107+ local_filepath_was_str = False
108+ if isinstance (self .local_filepath , str ):
109+ local_filepath_array = [self .local_filepath ]
110+ local_filepath_was_str = True
108111 else :
109- self . local_filepath = local_filepath
112+ local_filepath_array = self . local_filepath
110113
111- if isinstance (remote_filepath , str ):
112- self . remote_filepath = [remote_filepath ]
114+ if isinstance (self . remote_filepath , str ):
115+ remote_filepath_array = [self . remote_filepath ]
113116 else :
114- self . remote_filepath = remote_filepath
117+ remote_filepath_array = self . remote_filepath
115118
116- if len (self . local_filepath ) != len (self . remote_filepath ):
119+ if len (local_filepath_array ) != len (remote_filepath_array ):
117120 raise ValueError (
118- f"{ len (self . local_filepath )} paths in local_filepath "
119- f"!= { len (self . remote_filepath )} paths in remote_filepath"
121+ f"{ len (local_filepath_array )} paths in local_filepath "
122+ f"!= { len (remote_filepath_array )} paths in remote_filepath"
120123 )
121124
122125 if not (self .operation .lower () == SFTPOperation .GET or self .operation .lower () == SFTPOperation .PUT ):
@@ -145,7 +148,6 @@ def __init__(
145148 )
146149 self .sftp_hook = SFTPHook (ssh_hook = self .ssh_hook )
147150
148- def execute (self , context : Any ) -> str | list [str ] | None :
149151 file_msg = None
150152 try :
151153 if self .ssh_conn_id :
@@ -168,23 +170,23 @@ def execute(self, context: Any) -> str | list[str] | None:
168170 )
169171 self .sftp_hook .remote_host = self .remote_host
170172
171- for local_filepath , remote_filepath in zip (self . local_filepath , self . remote_filepath ):
173+ for _local_filepath , _remote_filepath in zip (local_filepath_array , remote_filepath_array ):
172174 if self .operation .lower () == SFTPOperation .GET :
173- local_folder = os .path .dirname (local_filepath )
175+ local_folder = os .path .dirname (_local_filepath )
174176 if self .create_intermediate_dirs :
175177 Path (local_folder ).mkdir (parents = True , exist_ok = True )
176- file_msg = f"from { remote_filepath } to { local_filepath } "
178+ file_msg = f"from { _remote_filepath } to { _local_filepath } "
177179 self .log .info ("Starting to transfer %s" , file_msg )
178- self .sftp_hook .retrieve_file (remote_filepath , local_filepath )
180+ self .sftp_hook .retrieve_file (_remote_filepath , _local_filepath )
179181 else :
180- remote_folder = os .path .dirname (remote_filepath )
182+ remote_folder = os .path .dirname (_remote_filepath )
181183 if self .create_intermediate_dirs :
182184 self .sftp_hook .create_directory (remote_folder )
183- file_msg = f"from { local_filepath } to { remote_filepath } "
185+ file_msg = f"from { _local_filepath } to { _remote_filepath } "
184186 self .log .info ("Starting to transfer file %s" , file_msg )
185- self .sftp_hook .store_file (remote_filepath , local_filepath , confirm = self .confirm )
187+ self .sftp_hook .store_file (_remote_filepath , _local_filepath , confirm = self .confirm )
186188
187189 except Exception as e :
188190 raise AirflowException (f"Error while transferring { file_msg } , error: { str (e )} " )
189191
190- return self . local_filepath [0 ] if self . local_filepath_was_str else self . local_filepath
192+ return local_filepath_array [0 ] if local_filepath_was_str else local_filepath_array
0 commit comments