2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

Merge pull request #2633 from greatroar/fix-ssh-commandline

Revert "Put host last in SSH command line"
This commit is contained in:
rawtaz 2020-03-08 17:29:41 +01:00 committed by GitHub
commit c542a509f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 10 deletions

View File

@ -189,8 +189,11 @@ func buildSSHCommand(cfg Config) (cmd string, args []string, err error) {
cmd = "ssh"
if cfg.Port != "" {
args = append(args, "-p", cfg.Port)
host, port := cfg.Host, cfg.Port
args = []string{host}
if port != "" {
args = append(args, "-p", port)
}
if cfg.User != "" {
args = append(args, "-l")
@ -198,8 +201,6 @@ func buildSSHCommand(cfg Config) (cmd string, args []string, err error) {
}
args = append(args, "-s")
args = append(args, "sftp")
args = append(args, "--", cfg.Host)
return cmd, args, nil
}

View File

@ -13,34 +13,34 @@ var sshcmdTests = []struct {
{
Config{User: "user", Host: "host", Path: "dir/subdir"},
"ssh",
[]string{"-l", "user", "-s", "sftp", "--", "host"},
[]string{"host", "-l", "user", "-s", "sftp"},
},
{
Config{Host: "host", Path: "dir/subdir"},
"ssh",
[]string{"-s", "sftp", "--", "host"},
[]string{"host", "-s", "sftp"},
},
{
Config{Host: "host", Port: "10022", Path: "/dir/subdir"},
"ssh",
[]string{"-p", "10022", "-s", "sftp", "--", "host"},
[]string{"host", "-p", "10022", "-s", "sftp"},
},
{
Config{User: "user", Host: "host", Port: "10022", Path: "/dir/subdir"},
"ssh",
[]string{"-p", "10022", "-l", "user", "-s", "sftp", "--", "host"},
[]string{"host", "-p", "10022", "-l", "user", "-s", "sftp"},
},
{
// IPv6 address.
Config{User: "user", Host: "::1", Path: "dir"},
"ssh",
[]string{"-l", "user", "-s", "sftp", "--", "::1"},
[]string{"::1", "-l", "user", "-s", "sftp"},
},
{
// IPv6 address with zone and port.
Config{User: "user", Host: "::1%lo0", Port: "22", Path: "dir"},
"ssh",
[]string{"-p", "22", "-l", "user", "-s", "sftp", "--", "::1%lo0"},
[]string{"::1%lo0", "-p", "22", "-l", "user", "-s", "sftp"},
},
}