File tree 1 file changed +18
-5
lines changed
1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
18
18
"strconv"
19
19
"strings"
20
20
21
+ "github.com/pkg/sftp"
21
22
"github.com/spf13/cobra"
22
23
"golang.org/x/crypto/ssh"
23
24
@@ -334,18 +335,30 @@ func (c *cmdFileDelete) Run(cmd *cobra.Command, args []string) error {
334
335
return err
335
336
}
336
337
338
+ // Store clients.
339
+ sftpClients := map [string ]* sftp.Client {}
340
+
341
+ defer func () {
342
+ for _ , sftpClient := range sftpClients {
343
+ sftpClient .Close ()
344
+ }
345
+ }()
346
+
337
347
for _ , resource := range resources {
338
348
pathSpec := strings .SplitN (resource .name , "/" , 2 )
339
349
if len (pathSpec ) != 2 {
340
350
return fmt .Errorf (i18n .G ("Invalid path %s" ), resource .name )
341
351
}
342
352
343
- sftpConn , err := resource .server .GetInstanceFileSFTP (pathSpec [0 ])
344
- if err != nil {
345
- return err
346
- }
353
+ sftpConn , ok := sftpClients [pathSpec [0 ]]
354
+ if ! ok {
355
+ sftpConn , err = resource .server .GetInstanceFileSFTP (pathSpec [0 ])
356
+ if err != nil {
357
+ return err
358
+ }
347
359
348
- defer func () { _ = sftpConn .Close () }()
360
+ sftpClients [pathSpec [0 ]] = sftpConn
361
+ }
349
362
350
363
if c .flagForce {
351
364
err = sftpConn .RemoveAll (pathSpec [1 ])
You can’t perform that action at this time.
0 commit comments