MCPcopy Create free account
hub / github.com/DBCDK/morph / sshArgs

Method sshArgs

ssh/ssh.go:78–122  ·  view source on GitHub ↗
(host Host, transfer *FileTransfer)

Source from the content-addressed store, hash-verified

76}
77
78func (ctx *SSHContext) sshArgs(host Host, transfer *FileTransfer) (cmd string, args []string) {
79 if transfer != nil {
80 cmd = "scp"
81 } else {
82 cmd = "ssh"
83 }
84 utils.ValidateEnvironment(cmd)
85
86 if ctx.SkipHostKeyCheck {
87 args = append(args,
88 "-o", "StrictHostKeyChecking=No",
89 "-o", "UserKnownHostsFile=/dev/null")
90 }
91 if ctx.IdentityFile != "" {
92 args = append(args, "-i")
93 args = append(args, ctx.IdentityFile)
94 }
95 if ctx.ConfigFile != "" {
96 args = append(args, "-F", ctx.ConfigFile)
97 }
98 var hostAndDestination = host.GetTargetHost()
99 if host.GetTargetPort() != 0 {
100 var optionName string
101 if transfer != nil {
102 optionName = "-P"
103 } else {
104 optionName = "-p"
105 }
106
107 args = append(args, optionName, fmt.Sprintf("%d", host.GetTargetPort()))
108 }
109
110 if transfer != nil {
111 args = append(args, transfer.Source)
112 hostAndDestination += ":" + transfer.Destination
113 }
114 if host.GetTargetUser() != "" {
115 hostAndDestination = host.GetTargetUser() + "@" + hostAndDestination
116 } else if ctx.DefaultUsername != "" {
117 hostAndDestination = ctx.DefaultUsername + "@" + hostAndDestination
118 }
119 args = append(args, hostAndDestination)
120
121 return
122}
123
124func (sshCtx *SSHContext) SudoCmd(host Host, parts ...string) (*exec.Cmd, error) {
125 return sshCtx.SudoCmdContext(context.TODO(), host, parts...)

Callers 3

CmdContextMethod · 0.95
SudoCmdContextMethod · 0.95
UploadFileMethod · 0.95

Calls 4

ValidateEnvironmentFunction · 0.92
GetTargetHostMethod · 0.65
GetTargetPortMethod · 0.65
GetTargetUserMethod · 0.65

Tested by

no test coverage detected