@@ -283,8 +283,10 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
283
283
mode = "r+b" if binary else "r+"
284
284
285
285
with tempfile .NamedTemporaryFile (mode = mode , delete = False ) as tmp_file :
286
+ scp_ssh_cmd = ['-P' if x == '-p' else x for x in self .ssh_cmd ]
287
+
286
288
if not truncate :
287
- scp_cmd = ['scp' ] + self . ssh_cmd + [f"{ self .username } @{ self .host } :{ filename } " , tmp_file .name ]
289
+ scp_cmd = ['scp' ] + scp_ssh_cmd + [f"{ self .username } @{ self .host } :{ filename } " , tmp_file .name ]
288
290
subprocess .run (scp_cmd , check = False ) # The file might not exist yet
289
291
tmp_file .seek (0 , os .SEEK_END )
290
292
@@ -300,11 +302,12 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
300
302
tmp_file .write (data )
301
303
302
304
tmp_file .flush ()
303
- scp_cmd = ['scp' ] + self .ssh_cmd + [tmp_file .name , f"{ self .username } @{ self .host } :{ filename } " ]
305
+ # Because in scp we set up port using -P option
306
+ scp_cmd = ['scp' ] + scp_ssh_cmd + [tmp_file .name , f"{ self .username } @{ self .host } :{ filename } " ]
304
307
subprocess .run (scp_cmd , check = True )
305
308
306
309
remote_directory = os .path .dirname (filename )
307
- mkdir_cmd = ['ssh' ] + self . ssh_cmd + [f"{ self .username } @{ self .host } " , f"mkdir -p { remote_directory } " ]
310
+ mkdir_cmd = ['ssh' ] + scp_ssh_cmd + [f"{ self .username } @{ self .host } " , f"mkdir -p { remote_directory } " ]
308
311
subprocess .run (mkdir_cmd , check = True )
309
312
310
313
os .remove (tmp_file .name )
0 commit comments