(host Host, transfer *FileTransfer)
| 76 | } |
| 77 | |
| 78 | func (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 | |
| 124 | func (sshCtx *SSHContext) SudoCmd(host Host, parts ...string) (*exec.Cmd, error) { |
| 125 | return sshCtx.SudoCmdContext(context.TODO(), host, parts...) |
no test coverage detected