@@ -182,12 +182,12 @@ def __init__( # noqa: PLR0913
182182 self .input_ports = FixedNumberOfInputs ([])
183183 self .output_port = FixedSchemaPort (schema = generate_list_schema ())
184184
185- def close_connections (self ) -> None :
185+ def cleanup_ssh_connections (self ) -> None :
186186 """Close connection from sftp and ssh"""
187187 self .sftp .close ()
188188 self .ssh_client .close ()
189189
190- def connect_ssh_client (self ) -> None :
190+ def establish_ssh_connection (self ) -> None :
191191 """Connect to the ssh client with the selected authentication method"""
192192 if self .authentication_method == "key" :
193193 self .ssh_client .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
@@ -211,6 +211,7 @@ def connect_ssh_client(self) -> None:
211211
212212 def preview_results (self ) -> str :
213213 """Preview the results of an execution"""
214+ self ._initialize_ssh_and_sftp_connections ()
214215 return preview_results (
215216 ssh_client = self .ssh_client ,
216217 no_subfolder = self .no_subfolder ,
@@ -220,6 +221,12 @@ def preview_results(self) -> str:
220221 max_workers = self .max_workers ,
221222 )
222223
224+ def _initialize_ssh_and_sftp_connections (self ) -> None :
225+ self .ssh_client = paramiko .SSHClient ()
226+ self .establish_ssh_connection ()
227+ self .sftp = self .ssh_client .open_sftp ()
228+
229+
223230 def execute (self , inputs : Sequence [Entities ], context : ExecutionContext ) -> Entities :
224231 """Execute the workflow task"""
225232 _ = inputs
@@ -228,9 +235,7 @@ def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> Enti
228235 )
229236 entities = []
230237
231- self .ssh_client = paramiko .SSHClient ()
232- self .connect_ssh_client ()
233- self .sftp = self .ssh_client .open_sftp ()
238+ self ._initialize_ssh_and_sftp_connections ()
234239
235240 retrieval = SSHRetrieval (
236241 ssh_client = self .ssh_client ,
@@ -320,7 +325,7 @@ def execute(self, inputs: Sequence[Entities], context: ExecutionContext) -> Enti
320325 )
321326 )
322327
323- self .close_connections ()
328+ self .cleanup_ssh_connections ()
324329
325330 return Entities (
326331 entities = iter (entities ),
0 commit comments