From cf05dac581b38e4ef7b5383fa2db1743f403a983 Mon Sep 17 00:00:00 2001 From: shoopea Date: Fri, 27 Dec 2024 23:13:26 +0100 Subject: [PATCH] add searches --- ftp.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ftp.go b/ftp.go index cfb648d..d62235b 100644 --- a/ftp.go +++ b/ftp.go @@ -8,7 +8,6 @@ import ( "context" "crypto/tls" "errors" - "fmt" "io" "net" "net/textproto" @@ -1102,10 +1101,8 @@ func (c *ServerConn) Search(pattern string) ([]string, error) { return nil, err } - fmt.Printf("SEARCH:\r\n-----------------------------------\r\n%s\r\n-----------------------------------\r\n", message) - msgs := make([]string, 0) - re := regexp.MustCompile(`^200- (?P.*) \(.*\).*$`) + re := regexp.MustCompile(`^[^\/]*(?P\/.*) \(.*\).*$`) for _, msg := range strings.Split(message, "\n") { if re.MatchString(msg) { msgs = append(msgs, re.ReplaceAllString(msg, "${Path}")) @@ -1115,6 +1112,20 @@ func (c *ServerConn) Search(pattern string) ([]string, error) { return msgs, nil } +// Search returns all the directories matching the search pattern +func (c *ServerConn) Searches(patterns []string) ([]string, error) { + msgs := make([]string, 0) + for _, pattern := range patterns { + msg, err := c.Search(pattern) + if err != nil { + return msgs, err + } + msgs = append(msgs, msg...) + } + + return msgs, nil +} + // NoOp issues a NOOP FTP command. // NOOP has no effects and is usually used to prevent the remote FTP server to // close the otherwise idle connection.