Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cf05dac581 | ||
|
b83b870ac3 | ||
|
edc371677f | ||
|
0d44b53277 | ||
|
1b970516f5 | ||
|
d0a6cb31a2 | ||
|
1c1a6e4887 | ||
|
ebfb9b5098 | ||
|
7844f623b3 | ||
|
2304047ac3 | ||
|
15617cd936 | ||
|
585184769d | ||
|
557e170e29 | ||
|
4edb16bfcd | ||
|
649c613fbc | ||
|
a93533d16c | ||
|
824fdbc882 | ||
|
678cef9c13 | ||
|
d019ddee92 | ||
|
a9581d60ae | ||
|
f58b250a0a | ||
|
bedccfb795 | ||
|
e44fc64e60 | ||
|
a58dc069db | ||
|
22efdfbe8a | ||
|
9226fc7f7c | ||
|
2b809c0747 |
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@ -41,11 +41,11 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4.1.7
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v2
|
uses: github/codeql-action/init@v3
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
@ -66,4 +66,4 @@ jobs:
|
|||||||
# ./location_of_script_within_repo/buildscript.sh
|
# ./location_of_script_within_repo/buildscript.sh
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@b398f525a5587552e573b247ac661067fafa920b
|
uses: github/codeql-action/analyze@64e61baeac852f409b48440cebec029a2d978f90
|
||||||
|
4
.github/workflows/golangci-lint.yaml
vendored
4
.github/workflows/golangci-lint.yaml
vendored
@ -9,8 +9,8 @@ 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@7884fcad6b5d53d10323aee724dc68d8b9096a2e
|
- uses: actions/checkout@v4.1.7
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5
|
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86
|
||||||
with:
|
with:
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
|
8
.github/workflows/unit_tests.yaml
vendored
8
.github/workflows/unit_tests.yaml
vendored
@ -5,12 +5,12 @@ jobs:
|
|||||||
name: test
|
name: test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@61b9e3751b92087fd0b06925ba6dd6314e06f089
|
- uses: actions/checkout@v4.1.7
|
||||||
- name: Setup go
|
- name: Setup go
|
||||||
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753
|
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32
|
||||||
with:
|
with:
|
||||||
go-version: 1.19
|
go-version: 1.19
|
||||||
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
|
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/go/pkg/mod
|
~/go/pkg/mod
|
||||||
@ -23,7 +23,7 @@ jobs:
|
|||||||
- name: Convert coverage to lcov
|
- name: Convert coverage to lcov
|
||||||
uses: jandelgado/gcov2lcov-action@c680c0f7c7442485f1749eb2a13e54a686e76eb5
|
uses: jandelgado/gcov2lcov-action@c680c0f7c7442485f1749eb2a13e54a686e76eb5
|
||||||
- name: Coveralls
|
- name: Coveralls
|
||||||
uses: coverallsapp/github-action@f350da2c033043742f89e8c0b7b5145a1616da6d
|
uses: coverallsapp/github-action@643bc377ffa44ace6394b2b5d0d3950076de9f63
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.github_token }}
|
github-token: ${{ secrets.github_token }}
|
||||||
path-to-lcov: coverage.lcov
|
path-to-lcov: coverage.lcov
|
||||||
|
52
ftp.go
52
ftp.go
@ -11,6 +11,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -528,9 +529,26 @@ func (c *ServerConn) pasv() (host string, port int, err error) {
|
|||||||
|
|
||||||
// Make the IP address to connect to
|
// Make the IP address to connect to
|
||||||
host = strings.Join(pasvData[0:4], ".")
|
host = strings.Join(pasvData[0:4], ".")
|
||||||
|
|
||||||
|
if c.host != host {
|
||||||
|
if cmdIP := net.ParseIP(c.host); cmdIP != nil {
|
||||||
|
if dataIP := net.ParseIP(host); dataIP != nil {
|
||||||
|
if isBogusDataIP(cmdIP, dataIP) {
|
||||||
|
return c.host, port, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return host, port, nil
|
return host, port, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isBogusDataIP(cmdIP, dataIP net.IP) bool {
|
||||||
|
// Logic stolen from lftp (https://github.com/lavv17/lftp/blob/d67fc14d085849a6b0418bb3e912fea2e94c18d1/src/ftpclass.cc#L769)
|
||||||
|
return dataIP.IsMulticast() ||
|
||||||
|
cmdIP.IsPrivate() != dataIP.IsPrivate() ||
|
||||||
|
cmdIP.IsLoopback() != dataIP.IsLoopback()
|
||||||
|
}
|
||||||
|
|
||||||
// getDataConnPort returns a host, port for a new data connection
|
// getDataConnPort returns a host, port for a new data connection
|
||||||
// it uses the best available method to do so
|
// it uses the best available method to do so
|
||||||
func (c *ServerConn) getDataConnPort() (string, int, error) {
|
func (c *ServerConn) getDataConnPort() (string, int, error) {
|
||||||
@ -810,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
|
||||||
@ -1076,6 +1094,38 @@ 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(`^[^\/]*(?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 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.
|
||||||
|
22
ftp_test.go
Normal file
22
ftp_test.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package ftp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBogusDataIP(t *testing.T) {
|
||||||
|
for _, tC := range []struct {
|
||||||
|
cmd, data net.IP
|
||||||
|
bogus bool
|
||||||
|
}{
|
||||||
|
{net.IPv4(192, 168, 1, 1), net.IPv4(192, 168, 1, 1), false},
|
||||||
|
{net.IPv4(192, 168, 1, 1), net.IPv4(1, 1, 1, 1), true},
|
||||||
|
{net.IPv4(10, 65, 1, 1), net.IPv4(1, 1, 1, 1), true},
|
||||||
|
{net.IPv4(10, 65, 25, 1), net.IPv4(10, 65, 8, 1), false},
|
||||||
|
} {
|
||||||
|
if got, want := isBogusDataIP(tC.cmd, tC.data), tC.bogus; got != want {
|
||||||
|
t.Errorf("%s,%s got %t, wanted %t", tC.cmd, tC.data, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
6
go.mod
6
go.mod
@ -1,10 +1,10 @@
|
|||||||
module github.com/jlaffaye/ftp
|
module git.siteop.biz/brouzouf/ftp
|
||||||
|
|
||||||
go 1.17
|
go 1.23.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/hashicorp/go-multierror v1.1.1
|
github.com/hashicorp/go-multierror v1.1.1
|
||||||
github.com/stretchr/testify v1.8.3
|
github.com/stretchr/testify v1.10.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
11
go.sum
11
go.sum
@ -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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
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=
|
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
||||||
@ -7,15 +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/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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
||||||
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.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
|
|
||||||
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
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/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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
2
parse.go
2
parse.go
@ -24,6 +24,8 @@ var listLineParsers = []parseFunc{
|
|||||||
var dirTimeFormats = []string{
|
var dirTimeFormats = []string{
|
||||||
"01-02-06 03:04PM",
|
"01-02-06 03:04PM",
|
||||||
"2006-01-02 15:04",
|
"2006-01-02 15:04",
|
||||||
|
"01-02-2006 03:04PM",
|
||||||
|
"01-02-2006 15:04",
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseRFC3659ListLine parses the style of directory line defined in RFC 3659.
|
// parseRFC3659ListLine parses the style of directory line defined in RFC 3659.
|
||||||
|
@ -68,7 +68,9 @@ var listTests = []line{
|
|||||||
// DOS DIR command output
|
// DOS DIR command output
|
||||||
{"08-07-15 07:50PM 718 Post_PRR_20150901_1166_265118_13049.dat", "Post_PRR_20150901_1166_265118_13049.dat", 718, EntryTypeFile, newTime(2015, time.August, 7, 19, 50)},
|
{"08-07-15 07:50PM 718 Post_PRR_20150901_1166_265118_13049.dat", "Post_PRR_20150901_1166_265118_13049.dat", 718, EntryTypeFile, newTime(2015, time.August, 7, 19, 50)},
|
||||||
{"08-10-15 02:04PM <DIR> Billing", "Billing", 0, EntryTypeFolder, newTime(2015, time.August, 10, 14, 4)},
|
{"08-10-15 02:04PM <DIR> Billing", "Billing", 0, EntryTypeFolder, newTime(2015, time.August, 10, 14, 4)},
|
||||||
|
{"08-07-2015 07:50PM 718 Post_PRR_20150901_1166_265118_13049.dat", "Post_PRR_20150901_1166_265118_13049.dat", 718, EntryTypeFile, newTime(2015, time.August, 7, 19, 50)},
|
||||||
|
{"08-10-2015 02:04PM <DIR> Billing", "Billing", 0, EntryTypeFolder, newTime(2015, time.August, 10, 14, 4)},
|
||||||
|
|
||||||
// dir and file names that contain multiple spaces
|
// dir and file names that contain multiple spaces
|
||||||
{"drwxr-xr-x 3 110 1002 3 Dec 02 2009 spaces dir name", "spaces dir name", 0, EntryTypeFolder, newTime(2009, time.December, 2)},
|
{"drwxr-xr-x 3 110 1002 3 Dec 02 2009 spaces dir name", "spaces dir name", 0, EntryTypeFolder, newTime(2009, time.December, 2)},
|
||||||
{"-rwxr-xr-x 3 110 1002 1234567 Dec 02 2009 file name", "file name", 1234567, EntryTypeFile, newTime(2009, time.December, 2)},
|
{"-rwxr-xr-x 3 110 1002 1234567 Dec 02 2009 file name", "file name", 1234567, EntryTypeFile, newTime(2009, time.December, 2)},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user