summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-04-11 21:51:38 +0700
committerShulhan <ms@kilabit.info>2021-04-11 21:51:38 +0700
commitcf068885fdf1f25e9e53ee2b89e09ba29393c1d3 (patch)
tree220db83b4f63746753661000a24a2a0bca246075
parentba20dd55c85a0222a776bcddf2e563d34d1a4dbe (diff)
downloadpakakeh.go-cf068885fdf1f25e9e53ee2b89e09ba29393c1d3.tar.xz
ssh: check for empty private key file on Get and Put
If the private key file is empty, skip it for being added as parameter of scp command. This is to prevent warning message on user side.
-rw-r--r--lib/ssh/client.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/ssh/client.go b/lib/ssh/client.go
index 184b2e45..419f3682 100644
--- a/lib/ssh/client.go
+++ b/lib/ssh/client.go
@@ -132,8 +132,15 @@ func (cl *Client) Get(remote, local string) (err error) {
remote = fmt.Sprintf("%s@%s:%s", cl.cfg.User, cl.cfg.Hostname, remote)
- cmd := exec.Command("scp", "-r", "-i", cl.cfg.privateKeyFile,
- "-P", cl.cfg.stringPort, remote, local)
+ args := []string{"-r", "-P", cl.cfg.stringPort}
+ if len(cl.cfg.privateKeyFile) > 0 {
+ args = append(args, "-i")
+ args = append(args, cl.cfg.privateKeyFile)
+ }
+ args = append(args, remote)
+ args = append(args, local)
+
+ cmd := exec.Command("scp", args...)
cmd.Dir = cl.cfg.workingDir
cmd.Stdout = os.Stdout
@@ -165,8 +172,15 @@ func (cl *Client) Put(local, remote string) (err error) {
remote = fmt.Sprintf("%s@%s:%s", cl.cfg.User, cl.cfg.Hostname, remote)
- cmd := exec.Command("scp", "-r", "-i", cl.cfg.privateKeyFile,
- "-P", cl.cfg.stringPort, local, remote)
+ args := []string{"-r", "-P", cl.cfg.stringPort}
+ if len(cl.cfg.privateKeyFile) > 0 {
+ args = append(args, "-i")
+ args = append(args, cl.cfg.privateKeyFile)
+ }
+ args = append(args, local)
+ args = append(args, remote)
+
+ cmd := exec.Command("scp", args...)
cmd.Dir = cl.cfg.workingDir
cmd.Stdout = os.Stdout