@@ -14,6 +14,7 @@ import (
14
14
"path/filepath"
15
15
"regexp"
16
16
"runtime"
17
+ "strconv"
17
18
"strings"
18
19
"time"
19
20
@@ -29,8 +30,10 @@ var Busy = false
29
30
30
31
// Auth contains username and password used for a network upload
31
32
type Auth struct {
32
- Username string `json:"username"`
33
- Password string `json:"password"`
33
+ Username string `json:"username"`
34
+ Password string `json:"password"`
35
+ PrivateKey string `json:"private_key"`
36
+ Port int `json:"port"`
34
37
}
35
38
36
39
// Extra contains some options used during the upload
@@ -375,8 +378,19 @@ func form(port, board, file string, auth Auth, l Logger) error {
375
378
func ssh (port string , files []string , commandline string , auth Auth , l Logger , SSH bool ) error {
376
379
debug (l , "Connect via ssh " , files , commandline )
377
380
381
+ if auth .Port == 0 {
382
+ auth .Port = 22
383
+ }
384
+
378
385
// Connect via ssh
379
- client , err := simplessh .ConnectWithPassword (port + ":22" , auth .Username , auth .Password )
386
+ var client * simplessh.Client
387
+ var err error
388
+ if auth .PrivateKey != "" {
389
+ client , err = simplessh .ConnectWithKey (port + ":" + strconv .Itoa (auth .Port ), auth .Username , auth .PrivateKey )
390
+ } else {
391
+ client , err = simplessh .ConnectWithPassword (port + ":" + strconv .Itoa (auth .Port ), auth .Username , auth .Password )
392
+ }
393
+
380
394
if err != nil {
381
395
return errors .Wrapf (err , "Connect via ssh" )
382
396
}
0 commit comments