From f39fed1a4b8c7f0ee370125dc11a25aa6b0906cf Mon Sep 17 00:00:00 2001 From: Dingjun Date: Sat, 16 Sep 2017 10:28:56 +0800 Subject: [PATCH] use dialer --- obfscp/scp.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/obfscp/scp.go b/obfscp/scp.go index 986a373..823253e 100644 --- a/obfscp/scp.go +++ b/obfscp/scp.go @@ -36,6 +36,8 @@ type options struct { PrivateKey string } +var dialer = &net.Dialer{Timeout: 10 * time.Second} + func main() { var cfg options flag.Usage = usage @@ -158,12 +160,12 @@ func createSFTPConn(host, user string, cfg *options) (*sftp.Client, error) { var c net.Conn var err error if cfg.TLS { - c, err = tls.Dial("tcp", rhost, &tls.Config{ + c, err = tls.DialWithDialer(dialer, "tcp", rhost, &tls.Config{ ServerName: host, InsecureSkipVerify: cfg.TLSInsecure, }) } else { - c, err = net.Dial("tcp", rhost) + c, err = dialer.Dial("tcp", rhost) } if err != nil {