From 2eda7cdba53bf07339e9f1218d10039d7e0f2917 Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Fri, 7 Jul 2017 17:07:58 +0200 Subject: [PATCH] Allow login with private key and on a different port --- upload/upload.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/upload/upload.go b/upload/upload.go index d1b29a2e5..e01746c1f 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -14,6 +14,7 @@ import ( "path/filepath" "regexp" "runtime" + "strconv" "strings" "time" @@ -29,8 +30,10 @@ var Busy = false // Auth contains username and password used for a network upload type Auth struct { - Username string `json:"username"` - Password string `json:"password"` + Username string `json:"username"` + Password string `json:"password"` + PrivateKey string `json:"private_key"` + Port int `json:"port"` } // Extra contains some options used during the upload @@ -375,8 +378,19 @@ func form(port, board, file string, auth Auth, l Logger) error { func ssh(port string, files []string, commandline string, auth Auth, l Logger, SSH bool) error { debug(l, "Connect via ssh ", files, commandline) + if auth.Port == 0 { + auth.Port = 22 + } + // Connect via ssh - client, err := simplessh.ConnectWithPassword(port+":22", auth.Username, auth.Password) + var client *simplessh.Client + var err error + if auth.PrivateKey != "" { + client, err = simplessh.ConnectWithKey(port+":"+strconv.Itoa(auth.Port), auth.Username, auth.PrivateKey) + } else { + client, err = simplessh.ConnectWithPassword(port+":"+strconv.Itoa(auth.Port), auth.Username, auth.Password) + } + if err != nil { return errors.Wrapf(err, "Connect via ssh") }