add search
This commit is contained in:
parent
1b970516f5
commit
0d44b53277
21
ftp.go
21
ftp.go
@ -11,6 +11,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/textproto"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -827,7 +828,7 @@ func (c *ServerConn) CurrentDir() (string, error) {
|
||||
end := strings.LastIndex(msg, "\"")
|
||||
|
||||
if start == -1 || end == -1 {
|
||||
return "", errors.New("unsuported PWD response format")
|
||||
return "", errors.New("unsupported PWD response format")
|
||||
}
|
||||
|
||||
return msg[start+1 : end], nil
|
||||
@ -1093,6 +1094,24 @@ func (c *ServerConn) Walk(root string) *Walker {
|
||||
return w
|
||||
}
|
||||
|
||||
// Search returns all the directories matching the search pattern
|
||||
func (c *ServerConn) Search(pattern string) ([]string, error) {
|
||||
_, message, err := c.cmd(StatusCommandOK, "SITE SEARCH %s", pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
msgs := make([]string, 0)
|
||||
re := regexp.MustCompile(`^200- (?P<Path>.*) \(.*\).*$`)
|
||||
for _, msg := range strings.Split(message, "\n") {
|
||||
if re.MatchString(msg) {
|
||||
msgs = append(msgs, re.ReplaceAllString(msg, "${Path}"))
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user