summaryrefslogtreecommitdiff
path: root/ssh_client.go
diff options
context:
space:
mode:
Diffstat (limited to 'ssh_client.go')
-rw-r--r--ssh_client.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/ssh_client.go b/ssh_client.go
index 766e40b..e47b47b 100644
--- a/ssh_client.go
+++ b/ssh_client.go
@@ -4,6 +4,7 @@
package awwan
import (
+ "errors"
"fmt"
"io/fs"
"path/filepath"
@@ -96,6 +97,30 @@ func (sshc *sshClient) chown(remoteFile, owner string) (err error) {
return nil
}
+// close the connections and release all resources.
+func (sshc *sshClient) close() (err error) {
+ err = sshc.rmdirAll(sshc.dirTmp)
+
+ var errClose error
+
+ if sshc.sftpc != nil {
+ errClose = sshc.sftpc.Close()
+ if errClose != nil {
+ err = errors.Join(err, errClose)
+ }
+ sshc.sftpc = nil
+ }
+
+ errClose = sshc.conn.Close()
+ if errClose != nil {
+ err = errors.Join(err, errClose)
+ }
+ sshc.conn = nil
+ sshc.section = nil
+
+ return err
+}
+
// get the remote file and write it to local path.
func (sshc *sshClient) get(remote, local string) (err error) {
if sshc.sftpc == nil {