Skip to content

Commit 2942ce6

Browse files
committed
feat(pkg/utils/exec_utils): Add method SCPRemoteToLocal
1 parent e7c3373 commit 2942ce6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pkg/utils/exec_utils/exec_utils.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ func rawSCP(taskInput libtask.TaskInput, localPath string, remotePath string) er
6060
return Exec(taskInput, "scp", args...)
6161
}
6262

63+
func rawSCPRemoteToLocal(taskInput libtask.TaskInput, remotePath string, localPath string) error {
64+
args := []string{taskInput.SSHTarget + ":" + remotePath, localPath}
65+
if taskInput.NoStrictHostKeyChecking {
66+
args = append([]string{"-o", "StrictHostKeyChecking=no"}, args...)
67+
}
68+
return Exec(taskInput, "scp", args...)
69+
}
70+
6371
func SCP(taskInput libtask.TaskInput, localSrc string, remoteDst string) error {
6472
var err error
6573
tmpPath := "/tmp/" + random_utils.RandomString(32)
@@ -73,3 +81,17 @@ func SCP(taskInput libtask.TaskInput, localSrc string, remoteDst string) error {
7381
)
7482
return err
7583
}
84+
85+
func SCPRemoteToLocal(taskInput libtask.TaskInput, remoteSrc string, localDst string) error {
86+
var err error
87+
tmpPath := "/tmp/" + random_utils.RandomString(32)
88+
err = SSH(
89+
taskInput,
90+
"cp", remoteSrc, tmpPath,
91+
)
92+
if err != nil {
93+
return err
94+
}
95+
err = rawSCPRemoteToLocal(taskInput, tmpPath, localDst)
96+
return err
97+
}

0 commit comments

Comments
 (0)