Skip to content

Commit

Permalink
Adding MODE support (#460)
Browse files Browse the repository at this point in the history
We're only accepting the "Stream" mode though. But at least it's official.

This addresses #451.
  • Loading branch information
fclairamb committed Jun 2, 2024
1 parent d2b3c25 commit 117fcb6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions handle_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ func (c *clientHandler) handleTYPE(param string) error {
return nil
}

func (c *clientHandler) handleMODE(param string) error {
if param == "S" {
c.writeMessage(StatusOK, "Using stream mode")
} else {
c.writeMessage(StatusNotImplementedParam, "Unsupported mode")
}

return nil
}

func (c *clientHandler) handleQUIT(_ string) error {
c.transferWg.Wait()

Expand Down
24 changes: 24 additions & 0 deletions handle_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,27 @@ func TestTYPE(t *testing.T) {
require.NoError(t, err)
require.Equal(t, StatusNotImplementedParam, returnCode)
}

func TestMode(t *testing.T) {
server := NewTestServer(t, false)
conf := goftp.Config{
User: authUser,
Password: authPass,
}

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

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

raw, err := client.OpenRawConn()
require.NoError(t, err, "Couldn't open raw connection")

returnCode, _, err := raw.SendCommand("MODE S")
require.NoError(t, err)
require.Equal(t, StatusOK, returnCode)

returnCode, _, err = raw.SendCommand("MODE X")
require.NoError(t, err)
require.Equal(t, StatusNotImplementedParam, returnCode)
}
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var commandsMap = map[string]*CommandDescription{ //nolint:gochecknoglobals

// Connection handling
"TYPE": {Fn: (*clientHandler).handleTYPE},
"MODE": {Fn: (*clientHandler).handleMODE},
"PASV": {Fn: (*clientHandler).handlePASV},
"EPSV": {Fn: (*clientHandler).handlePASV},
"PORT": {Fn: (*clientHandler).handlePORT},
Expand Down

0 comments on commit 117fcb6

Please sign in to comment.