* fix(sftp): reconnect to server when conn was broken (close #6403) * fix(sftp): fix typo --------- Co-authored-by: George Chen <gchen@isimarkets.com>
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/pkg/sftp"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
@ -30,6 +31,23 @@ func (d *SFTP) initClient() error {
|
||||
return err
|
||||
}
|
||||
d.client, err = sftp.NewClient(conn)
|
||||
if err == nil {
|
||||
d.clientConnectionError = nil
|
||||
go func(d *SFTP) {
|
||||
d.clientConnectionError = d.client.Wait()
|
||||
}(d)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *SFTP) clientReconnectOnConnectionError() error {
|
||||
err := d.clientConnectionError
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
log.Debugf("[sftp] discarding closed sftp connection: %v", err)
|
||||
_ = d.client.Close()
|
||||
err = d.initClient()
|
||||
return err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user