Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c2aa379fd | ||
|
|
f5852338bb | ||
|
|
36e873b513 | ||
|
|
0feadd74ba | ||
|
|
67ffbbc0de | ||
|
|
3eddb768d0 | ||
|
|
f568a0d846 | ||
|
|
d84bf4be2b | ||
|
|
9e39e2c406 | ||
|
|
58cb524052 | ||
|
|
0257a7bc42 | ||
|
|
5fc8c694ec | ||
|
|
b10ce93530 | ||
|
|
5b1ec4dc6c | ||
|
|
a0ec57882b | ||
|
|
917837ffbd | ||
|
|
6512c2a4ae | ||
|
|
a2b3f0878b | ||
|
|
b40593bd5a | ||
|
|
dca029e125 | ||
|
|
08a9ec380c | ||
|
|
260999f2de | ||
|
|
f1ba13192b | ||
|
|
9c3c2fd740 | ||
|
|
be12fe0263 |
4
.github/dependabot.yml
vendored
4
.github/dependabot.yml
vendored
@@ -11,3 +11,7 @@ updates:
|
||||
interval: "daily"
|
||||
assignees:
|
||||
- "jlaffaye"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
69
.github/workflows/codeql-analysis.yml
vendored
Normal file
69
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ "master" ]
|
||||
schedule:
|
||||
- cron: '20 19 * * 2'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'go' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
|
||||
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||
# queries: security-extended,security-and-quality
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
|
||||
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
||||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
||||
|
||||
# - run: |
|
||||
# echo "Run, Build Application using script"
|
||||
# ./location_of_script_within_repo/buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@b398f525a5587552e573b247ac661067fafa920b
|
||||
7
.github/workflows/golangci-lint.yaml
vendored
7
.github/workflows/golangci-lint.yaml
vendored
@@ -5,9 +5,12 @@ jobs:
|
||||
golangci-lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read # for actions/checkout to fetch code
|
||||
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5
|
||||
with:
|
||||
only-new-issues: true
|
||||
|
||||
12
.github/workflows/unit_tests.yaml
vendored
12
.github/workflows/unit_tests.yaml
vendored
@@ -5,12 +5,12 @@ jobs:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/checkout@61b9e3751b92087fd0b06925ba6dd6314e06f089
|
||||
- name: Setup go
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753
|
||||
with:
|
||||
go-version: 1.17
|
||||
- uses: actions/cache@v2
|
||||
go-version: 1.19
|
||||
- uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
|
||||
with:
|
||||
path: |
|
||||
~/go/pkg/mod
|
||||
@@ -21,9 +21,9 @@ jobs:
|
||||
- name: Run tests
|
||||
run: go test -v -covermode=count -coverprofile=coverage.out
|
||||
- name: Convert coverage to lcov
|
||||
uses: jandelgado/gcov2lcov-action@v1.0.8
|
||||
uses: jandelgado/gcov2lcov-action@c680c0f7c7442485f1749eb2a13e54a686e76eb5
|
||||
- name: Coveralls
|
||||
uses: coverallsapp/github-action@v1.1.2
|
||||
uses: coverallsapp/github-action@f350da2c033043742f89e8c0b7b5145a1616da6d
|
||||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
path-to-lcov: coverage.lcov
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
[](https://github.com/jlaffaye/ftp/actions/workflows/unit_tests.yaml)
|
||||
[](https://coveralls.io/github/jlaffaye/ftp?branch=master)
|
||||
[](https://github.com/jlaffaye/ftp/actions/workflows/golangci-lint.yaml)
|
||||
[](https://github.com/jlaffaye/ftp/actions/workflows/codeql-analysis.yml)
|
||||
[](http://goreportcard.com/report/jlaffaye/ftp)
|
||||
[](https://pkg.go.dev/github.com/jlaffaye/ftp)
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ func (mock *ftpMock) listen() {
|
||||
if cmdParts[1] == "multiline-dir" {
|
||||
mock.printfLine("250-File data\r\n Type=dir;Size=0; multiline-dir\r\n Modify=20201213202400; multiline-dir\r\n250 End")
|
||||
} else {
|
||||
mock.printfLine("250-File data\r\n Type=file;Size=42;Modify=20201213202400; magic-file\r\n250 End")
|
||||
mock.printfLine("250-File data\r\n Type=file;Size=42;Modify=20201213202400; magic-file\r\n \r\n250 End")
|
||||
}
|
||||
case "NLST":
|
||||
if mock.dataConn == nil {
|
||||
|
||||
38
ftp.go
38
ftp.go
@@ -559,7 +559,24 @@ func (c *ServerConn) openDataConn() (net.Conn, error) {
|
||||
}
|
||||
|
||||
if c.options.tlsConfig != nil {
|
||||
return tls.DialWithDialer(&c.options.dialer, "tcp", addr, c.options.tlsConfig)
|
||||
// We don't use tls.DialWithDialer here (which does Dial, create
|
||||
// the Client and then do the Handshake) because it seems to
|
||||
// hang with some FTP servers, namely proftpd and pureftpd.
|
||||
//
|
||||
// Instead we do Dial, create the Client and wait for the first
|
||||
// Read or Write to trigger the Handshake.
|
||||
//
|
||||
// This means that if we are uploading a zero sized file, we
|
||||
// need to make sure we do the Handshake explicitly as Write
|
||||
// won't have been called. This is done in StorFrom().
|
||||
//
|
||||
// See: https://github.com/jlaffaye/ftp/issues/282
|
||||
conn, err := c.options.dialer.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tlsConn := tls.Client(conn, c.options.tlsConfig)
|
||||
return tlsConn, nil
|
||||
}
|
||||
|
||||
return c.options.dialer.Dial("tcp", addr)
|
||||
@@ -749,6 +766,10 @@ func (c *ServerConn) GetEntry(path string) (entry *Entry, err error) {
|
||||
if len(l) > 0 && l[0] == ' ' {
|
||||
l = l[1:]
|
||||
}
|
||||
// Some severs seem to send a blank line at the end which we ignore
|
||||
if l == "" {
|
||||
continue
|
||||
}
|
||||
if e, err = parseNextRFC3659ListLine(l, c.options.location, e); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -912,8 +933,21 @@ func (c *ServerConn) StorFrom(path string, r io.Reader, offset uint64) error {
|
||||
// response otherwise if the failure is not due to a connection problem,
|
||||
// for example the server denied the upload for quota limits, we miss
|
||||
// the response and we cannot use the connection to send other commands.
|
||||
if _, err := io.Copy(conn, r); err != nil {
|
||||
if n, err := io.Copy(conn, r); err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
} else if n == 0 {
|
||||
// If we wrote no bytes and got no error, make sure we call
|
||||
// tls.Handshake on the connection as it won't get called
|
||||
// unless Write() is called. (See comment in openDataConn()).
|
||||
//
|
||||
// ProFTP doesn't like this and returns "Unable to build data
|
||||
// connection: Operation not permitted" when trying to upload
|
||||
// an empty file without this.
|
||||
if do, ok := conn.(interface{ Handshake() error }); ok {
|
||||
if err := do.Handshake(); err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := conn.Close(); err != nil {
|
||||
|
||||
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.17
|
||||
|
||||
require (
|
||||
github.com/hashicorp/go-multierror v1.1.1
|
||||
github.com/stretchr/testify v1.8.0
|
||||
github.com/stretchr/testify v1.8.3
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
4
go.sum
4
go.sum
@@ -9,9 +9,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
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/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
Reference in New Issue
Block a user