@@ -57,6 +57,11 @@ def __init__(self, conn_params: ConnectionParams):
5757 self .ssh_cmd += ["-p" , self .port ]
5858 self .remote = True
5959 self .username = conn_params .username or self .get_user ()
60+ < << << << HEAD
61+ == == == =
62+ self .ssh_dest = f"{ self .username } @{ self .host } " if self .username else "{self.host}"
63+ self .add_known_host (self .host )
64+ >> >> >> > default - ssh - user
6065 self .tunnel_process = None
6166 self .tunnel_port = None
6267
@@ -95,9 +100,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
95100 """
96101 ssh_cmd = []
97102 if isinstance (cmd , str ):
98- ssh_cmd = ['ssh' , f" { self .username } @ { self . host } " ] + self .ssh_cmd + [cmd ]
103+ ssh_cmd = ['ssh' , self .ssh_dest ] + self .ssh_cmd + [cmd ]
99104 elif isinstance (cmd , list ):
100- ssh_cmd = ['ssh' , f" { self .username } @ { self . host } " ] + self .ssh_cmd + cmd
105+ ssh_cmd = ['ssh' , self .ssh_dest ] + self .ssh_cmd + cmd
101106 process = subprocess .Popen (ssh_cmd , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
102107 if get_process :
103108 return process
@@ -246,9 +251,15 @@ def mkdtemp(self, prefix=None):
246251 - prefix (str): The prefix of the temporary directory name.
247252 """
248253 if prefix :
254+ < << << << HEAD
249255 command = ["ssh" + f"{ self .username } @{ self .host } " ] + self .ssh_cmd + [f"mktemp -d { prefix } XXXXX" ]
250256 else :
251257 command = ["ssh" , f"{ self .username } @{ self .host } " ] + self .ssh_cmd + ["mktemp -d" ]
258+ == == == =
259+ command = ["ssh" ] + self .ssh_cmd + [self .ssh_dest , f"mktemp -d { prefix } XXXXX" ]
260+ else :
261+ command = ["ssh" ] + self .ssh_cmd + [self .ssh_dest , "mktemp -d" ]
262+ >> >> >> > default - ssh - user
252263
253264 result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
254265
@@ -295,7 +306,11 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
295306 scp_ssh_cmd = ['-P' if x == '-p' else x for x in self .ssh_cmd ]
296307
297308 if not truncate :
309+ < << << << HEAD
298310 scp_cmd = ['scp' ] + scp_ssh_cmd + [f"{ self .username } @{ self .host } :{ filename } " , tmp_file .name ]
311+ == == == =
312+ scp_cmd = ['scp' ] + self .ssh_cmd + [f"{ self .ssh_dest } :{ filename } " , tmp_file .name ]
313+ >> >> >> > default - ssh - user
299314 subprocess .run (scp_cmd , check = False ) # The file might not exist yet
300315 tmp_file .seek (0 , os .SEEK_END )
301316
@@ -311,11 +326,19 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
311326 tmp_file .write (data )
312327
313328 tmp_file .flush ()
329+ < << << << HEAD
314330 scp_cmd = ['scp' ] + scp_ssh_cmd + [tmp_file .name , f"{ self .username } @{ self .host } :{ filename } " ]
315331 subprocess .run (scp_cmd , check = True )
316332
317333 remote_directory = os .path .dirname (filename )
318334 mkdir_cmd = ['ssh' , f"{ self .username } @{ self .host } " ] + self .ssh_cmd + [f"mkdir -p { remote_directory } " ]
335+ == == == =
336+ scp_cmd = ['scp' ] + self .ssh_cmd + [tmp_file .name , f"{ self .ssh_dest } :{ filename } " ]
337+ subprocess .run (scp_cmd , check = True )
338+
339+ remote_directory = os .path .dirname (filename )
340+ mkdir_cmd = ['ssh' ] + self .ssh_cmd + [self .ssh_dest , f"mkdir -p { remote_directory } " ]
341+ >> >> >> > default - ssh - user
319342 subprocess .run (mkdir_cmd , check = True )
320343
321344 os .remove (tmp_file .name )
@@ -380,7 +403,7 @@ def get_pid(self):
380403 return int (self .exec_command ("echo $$" , encoding = get_default_encoding ()))
381404
382405 def get_process_children (self , pid ):
383- command = ["ssh" , f" { self . username } @ { self . host } " ] + self .ssh_cmd + [f"pgrep -P { pid } " ]
406+ command = ["ssh" ] + self .ssh_cmd + [self . ssh_dest , f"pgrep -P { pid } " ]
384407
385408 result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
386409
0 commit comments