Skip to content

Commit

Permalink
fix: MLSD and MLST commands should write UTC timestamps (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottodashadow authored Jun 2, 2021
1 parent fdbef8d commit 66eae80
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion handle_dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (c *clientHandler) writeMLSxOutput(w io.Writer, file os.FileInfo) error {
"Type=%s;Size=%d;Modify=%s; %s\r\n",
listType,
file.Size(),
file.ModTime().Format(dateFormatMLSD),
file.ModTime().UTC().Format(dateFormatMLSD),
file.Name(),
)

Expand Down
33 changes: 33 additions & 0 deletions handle_dirs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/tls"
"fmt"
"net"
"os"
"path"
"testing"
"time"
Expand All @@ -14,6 +15,18 @@ import (

const DirKnown = "known"

func TestMain(m *testing.M) {
loc, err := time.LoadLocation("America/New_York")
if err != nil {
fmt.Printf("unable to set timezone: %v\n", err)
os.Exit(1)
}

time.Local = loc

os.Exit(m.Run())
}

func TestDirListing(t *testing.T) {
// MLSD is disabled we relies on LIST of files listing
s := NewTestServerWithDriver(t, &TestServerDriver{Debug: true, Settings: &Settings{DisableMLSD: true}})
Expand Down Expand Up @@ -448,3 +461,23 @@ func testListDirArgs(t *testing.T, s *FtpServer) {
require.NoError(t, err)
}
}

func TestMLSDTimezone(t *testing.T) {
s := NewTestServer(t, true)
conf := goftp.Config{
User: authUser,
Password: authPass,
}

c, err := goftp.DialConfig(conf, s.Addr())
require.NoError(t, err, "Couldn't connect")

defer func() { panicOnError(c.Close()) }()

ftpUpload(t, c, createTemporaryFile(t, 10), "file")
contents, err := c.ReadDir("/")
require.NoError(t, err)
require.Len(t, contents, 1)
require.Equal(t, "file", contents[0].Name())
require.InDelta(t, time.Now().Unix(), contents[0].ModTime().Unix(), 5)
}

0 comments on commit 66eae80

Please sign in to comment.