From bfe95d72207b91abda82ec1eefdf00a53187b5ee Mon Sep 17 00:00:00 2001 From: bruceauyeung Date: Thu, 9 Mar 2017 10:59:30 +0800 Subject: [PATCH 1/2] fix : potential nil err while w is not created successfully --- easyssh.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/easyssh.go b/easyssh.go index c530eea..f185e69 100644 --- a/easyssh.go +++ b/easyssh.go @@ -203,17 +203,19 @@ func (ssh_conf *MakeConfig) Scp(sourceFile string, etargetFile string) error { } go func() { - w, _ := session.StdinPipe() + w, err := session.StdinPipe() + if err != nil { + return + } + defer w.Close() fmt.Fprintln(w, "C0644", srcStat.Size(), targetFile) if srcStat.Size() > 0 { io.Copy(w, src) fmt.Fprint(w, "\x00") - w.Close() } else { fmt.Fprint(w, "\x00") - w.Close() } }() From afd29a4a9b45d3c433cb6834579e1135bdaf6884 Mon Sep 17 00:00:00 2001 From: bruceauyeung Date: Tue, 14 Mar 2017 09:51:12 +0800 Subject: [PATCH 2/2] add timeout for establishing tcp connection --- easyssh.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/easyssh.go b/easyssh.go index f185e69..4fa5e51 100644 --- a/easyssh.go +++ b/easyssh.go @@ -32,6 +32,9 @@ type MakeConfig struct { Key string Port string Password string + // Timeout is the maximum amount of time for the TCP connection to establish. + // A Timeout of zero means no timeout. + Timeout time.Duration } // returns ssh.Signer from user you running app home path + cutted key path. @@ -76,8 +79,9 @@ func (ssh_conf *MakeConfig) connect() (*ssh.Session, error) { } config := &ssh.ClientConfig{ - User: ssh_conf.User, - Auth: auths, + User: ssh_conf.User, + Auth: auths, + Timeout: ssh_conf.Timeout, } client, err := ssh.Dial("tcp", ssh_conf.Server+":"+ssh_conf.Port, config)