Skip to content

Commit d08325b

Browse files
author
vshepard
committed
Add port to scp command
1 parent da22340 commit d08325b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

testgres/operations/remote_ops.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
285285
mode = "r+b" if binary else "r+"
286286

287287
with tempfile.NamedTemporaryFile(mode=mode, delete=False) as tmp_file:
288+
scp_ssh_cmd = ['-P' if x == '-p' else x for x in self.ssh_cmd]
289+
288290
if not truncate:
289-
scp_cmd = ['scp'] + self.ssh_cmd + [f"{self.username}@{self.host}:{filename}", tmp_file.name]
291+
scp_cmd = ['scp'] + scp_ssh_cmd + [f"{self.username}@{self.host}:{filename}", tmp_file.name]
290292
subprocess.run(scp_cmd, check=False) # The file might not exist yet
291293
tmp_file.seek(0, os.SEEK_END)
292294

@@ -302,11 +304,12 @@ def write(self, filename, data, truncate=False, binary=False, read_and_write=Fal
302304
tmp_file.write(data)
303305

304306
tmp_file.flush()
305-
scp_cmd = ['scp'] + self.ssh_cmd + [tmp_file.name, f"{self.username}@{self.host}:{filename}"]
307+
# Because in scp we set up port using -P option
308+
scp_cmd = ['scp'] + scp_ssh_cmd + [tmp_file.name, f"{self.username}@{self.host}:{filename}"]
306309
subprocess.run(scp_cmd, check=True)
307310

308311
remote_directory = os.path.dirname(filename)
309-
mkdir_cmd = ['ssh'] + self.ssh_cmd + [f"{self.username}@{self.host}", f"mkdir -p {remote_directory}"]
312+
mkdir_cmd = ['ssh'] + scp_ssh_cmd + [f"{self.username}@{self.host}", f"mkdir -p {remote_directory}"]
310313
subprocess.run(mkdir_cmd, check=True)
311314

312315
os.remove(tmp_file.name)

testgres/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ def execute_utility(args, logfile=None, verbose=False):
7474

7575
# write new log entry if possible
7676
if logfile:
77-
if not tconf.os_ops.path_exists(logfile):
78-
tconf.os_ops.touch(logfile)
7977
try:
8078
tconf.os_ops.write(filename=logfile, data=args, truncate=True)
8179
if out:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy