@@ -57,6 +57,11 @@ def __init__(self, conn_params: ConnectionParams):
57
57
self .ssh_cmd += ["-p" , self .port ]
58
58
self .remote = True
59
59
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
60
65
self .tunnel_process = None
61
66
self .tunnel_port = None
62
67
@@ -95,9 +100,9 @@ def exec_command(self, cmd, wait_exit=False, verbose=False, expect_error=False,
95
100
"""
96
101
ssh_cmd = []
97
102
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 ]
99
104
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
101
106
process = subprocess .Popen (ssh_cmd , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
102
107
if get_process :
103
108
return process
@@ -246,9 +251,15 @@ def mkdtemp(self, prefix=None):
246
251
- prefix (str): The prefix of the temporary directory name.
247
252
"""
248
253
if prefix :
254
+ < << << << HEAD
249
255
command = ["ssh" + f"{ self .username } @{ self .host } " ] + self .ssh_cmd + [f"mktemp -d { prefix } XXXXX" ]
250
256
else :
251
257
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
252
263
253
264
result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
254
265
@@ -295,7 +306,11 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
295
306
scp_ssh_cmd = ['-P' if x == '-p' else x for x in self .ssh_cmd ]
296
307
297
308
if not truncate :
309
+ < << << << HEAD
298
310
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
299
314
subprocess .run (scp_cmd , check = False ) # The file might not exist yet
300
315
tmp_file .seek (0 , os .SEEK_END )
301
316
@@ -311,11 +326,19 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
311
326
tmp_file .write (data )
312
327
313
328
tmp_file .flush ()
329
+ < << << << HEAD
314
330
scp_cmd = ['scp' ] + scp_ssh_cmd + [tmp_file .name , f"{ self .username } @{ self .host } :{ filename } " ]
315
331
subprocess .run (scp_cmd , check = True )
316
332
317
333
remote_directory = os .path .dirname (filename )
318
334
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
319
342
subprocess .run (mkdir_cmd , check = True )
320
343
321
344
os .remove (tmp_file .name )
@@ -380,7 +403,7 @@ def get_pid(self):
380
403
return int (self .exec_command ("echo $$" , encoding = get_default_encoding ()))
381
404
382
405
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 } " ]
384
407
385
408
result = subprocess .run (command , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
386
409
0 commit comments