2 Commits

Author SHA1 Message Date
shoopea
5c76476bb4 add max limit for searches
Some checks failed
golangci-lint / lint (push) Has been cancelled
Units tests / test (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
2025-12-06 11:01:28 +01:00
shoopea
cf05dac581 add searches
Some checks failed
golangci-lint / lint (push) Has been cancelled
Units tests / test (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
2024-12-27 23:13:26 +01:00

21
ftp.go
View File

@@ -8,7 +8,6 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt"
"io" "io"
"net" "net"
"net/textproto" "net/textproto"
@@ -1097,15 +1096,13 @@ func (c *ServerConn) Walk(root string) *Walker {
// Search returns all the directories matching the search pattern // Search returns all the directories matching the search pattern
func (c *ServerConn) Search(pattern string) ([]string, error) { func (c *ServerConn) Search(pattern string) ([]string, error) {
_, message, err := c.cmd(StatusCommandOK, "SITE SEARCH %s", pattern) _, message, err := c.cmd(StatusCommandOK, "SITE SEARCH %s --LIMIT 50000", pattern)
if err != nil { if err != nil {
return nil, err return nil, err
} }
fmt.Printf("SEARCH:\r\n-----------------------------------\r\n%s\r\n-----------------------------------\r\n", message)
msgs := make([]string, 0) msgs := make([]string, 0)
re := regexp.MustCompile(`^200- (?P<Path>.*) \(.*\).*$`) re := regexp.MustCompile(`^[^\/]*(?P<Path>\/.*) \(.*\).*$`)
for _, msg := range strings.Split(message, "\n") { for _, msg := range strings.Split(message, "\n") {
if re.MatchString(msg) { if re.MatchString(msg) {
msgs = append(msgs, re.ReplaceAllString(msg, "${Path}")) msgs = append(msgs, re.ReplaceAllString(msg, "${Path}"))
@@ -1115,6 +1112,20 @@ func (c *ServerConn) Search(pattern string) ([]string, error) {
return msgs, nil 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 issues a NOOP FTP command.
// NOOP has no effects and is usually used to prevent the remote FTP server to // NOOP has no effects and is usually used to prevent the remote FTP server to
// close the otherwise idle connection. // close the otherwise idle connection.