Compare commits

..

4 Commits

Author SHA1 Message Date
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
shoopea
b83b870ac3 debug
Some checks failed
CodeQL / Analyze (go) (push) Waiting to run
golangci-lint / lint (push) Has been cancelled
Units tests / test (push) Has been cancelled
2024-12-27 23:07:11 +01:00
shoopea
edc371677f fix mod reference
Some checks failed
CodeQL / Analyze (go) (push) Waiting to run
golangci-lint / lint (push) Has been cancelled
Units tests / test (push) Has been cancelled
2024-12-27 22:58:57 +01:00
shoopea
0d44b53277 add search
Some checks failed
CodeQL / Analyze (go) (push) Waiting to run
golangci-lint / lint (push) Has been cancelled
Units tests / test (push) Has been cancelled
2024-12-27 22:48:28 +01:00
3 changed files with 36 additions and 12 deletions

35
ftp.go
View File

@ -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,38 @@ 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(`^[^\/]*(?P<Path>\/.*) \(.*\).*$`)
for _, msg := range strings.Split(message, "\n") {
if re.MatchString(msg) {
msgs = append(msgs, re.ReplaceAllString(msg, "${Path}"))
}
}
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.

4
go.mod
View File

@ -1,6 +1,6 @@
module github.com/jlaffaye/ftp
module git.siteop.biz/brouzouf/ftp
go 1.17
go 1.23.2
require (
github.com/hashicorp/go-multierror v1.1.1

9
go.sum
View File

@ -1,4 +1,3 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
@ -7,17 +6,9 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=