1 Commits

Author SHA1 Message Date
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
4 changed files with 23 additions and 4 deletions

View File

@@ -41,7 +41,7 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4.2.2 uses: actions/checkout@v4.1.7
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL

View File

@@ -9,7 +9,7 @@ jobs:
contents: read # for actions/checkout to fetch code contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
steps: steps:
- uses: actions/checkout@v4.2.2 - uses: actions/checkout@v4.1.7
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86
with: with:

View File

@@ -5,7 +5,7 @@ jobs:
name: test name: test
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4.2.2 - uses: actions/checkout@v4.1.7
- name: Setup go - name: Setup go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
with: with:

21
ftp.go
View File

@@ -11,6 +11,7 @@ import (
"io" "io"
"net" "net"
"net/textproto" "net/textproto"
"regexp"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@@ -827,7 +828,7 @@ func (c *ServerConn) CurrentDir() (string, error) {
end := strings.LastIndex(msg, "\"") end := strings.LastIndex(msg, "\"")
if start == -1 || end == -1 { 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 return msg[start+1 : end], nil
@@ -1093,6 +1094,24 @@ func (c *ServerConn) Walk(root string) *Walker {
return w 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 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.