Skip to content

Commit

Permalink
feat(exec_utils): Add sshpass support for scp #19
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejsika committed Jan 27, 2024
1 parent 9f89bc3 commit b986118
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/utils/exec_utils/exec_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,23 @@ func rawSCP(taskInput libtask.TaskInput, localPath string, remotePath string) er
if taskInput.NoStrictHostKeyChecking {
args = append([]string{"-o", "StrictHostKeyChecking=no"}, args...)
}
return Exec(taskInput, "scp", args...)
if taskInput.SSHPassword != "" {
return Exec(taskInput, "sshpass", append([]string{"-p", taskInput.SSHPassword, "scp"}, args...)...)
} else {
return Exec(taskInput, "scp", args...)
}
}

func rawSCPRemoteToLocal(taskInput libtask.TaskInput, remotePath string, localPath string) error {
args := []string{taskInput.SSHTarget + ":" + remotePath, localPath}
if taskInput.NoStrictHostKeyChecking {
args = append([]string{"-o", "StrictHostKeyChecking=no"}, args...)
}
return Exec(taskInput, "scp", args...)
if taskInput.SSHPassword != "" {
return Exec(taskInput, "sshpass", append([]string{"-p", taskInput.SSHPassword, "scp"}, args...)...)
} else {
return Exec(taskInput, "scp", args...)
}
}

func SCP(taskInput libtask.TaskInput, localSrc string, remoteDst string) error {
Expand Down

0 comments on commit b986118

Please # to comment.