diff --git a/handle_dirs.go b/handle_dirs.go index 44af3e03..b221dc14 100644 --- a/handle_dirs.go +++ b/handle_dirs.go @@ -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(), ) diff --git a/handle_dirs_test.go b/handle_dirs_test.go index 419ecd84..fd293afb 100644 --- a/handle_dirs_test.go +++ b/handle_dirs_test.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "fmt" "net" + "os" "path" "testing" "time" @@ -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}}) @@ -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) +}