Skip to content

Commit 7e9988e

Browse files
authored
Always 200 for OPTS UTF8 or OPTS UTF-8 ON (#676)
1 parent 4381bfc commit 7e9988e

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Bug tracker at https://github.com/giampaolo/pyftpdlib/issues
33
Version: 2.2.0 - XXXX-XX-XX
44
===========================
55

6+
**Bug fixes**
7+
8+
* #676: Always return 200 for the ``OPTS UTF8`` and ``OPTS UTF-8 ON`` commands
9+
to ensure correct FTP client compatibility when UTF-8 is supported.
610

711
**Compatibility notes**
812

pyftpdlib/handlers/ftp/control.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,22 +2224,24 @@ def ftp_OPTS(self, line):
22242224
raise ValueError("Invalid number of arguments")
22252225
if " " in line:
22262226
cmd, arg = line.split(" ")
2227-
if ";" not in arg:
2228-
raise ValueError("Invalid argument")
22292227
else:
22302228
cmd, arg = line, ""
2231-
# actually the only command able to accept options is MLST
2232-
if cmd.upper() != "MLST" or "MLST" not in self.proto_cmds:
2229+
# the only commands able to accept options are MLST and UTF8
2230+
if cmd.upper() in ("UTF8", "UTF-8"):
2231+
self.respond('200 Always in UTF8 mode.')
2232+
elif cmd.upper() == "MLST" and "MLST" in self.proto_cmds:
2233+
if arg and ';' not in arg:
2234+
raise ValueError('Invalid argument')
2235+
facts = [x.lower() for x in arg.split(";")]
2236+
self._current_facts = [
2237+
x for x in facts if x in self._available_facts
2238+
]
2239+
f = "".join([x + ";" for x in self._current_facts])
2240+
self.respond("200 MLST OPTS " + f)
2241+
else:
22332242
raise ValueError(f'Unsupported command "{cmd}"')
22342243
except ValueError as err:
22352244
self.respond(f"501 {err}.")
2236-
else:
2237-
facts = [x.lower() for x in arg.split(";")]
2238-
self._current_facts = [
2239-
x for x in facts if x in self._available_facts
2240-
]
2241-
f = "".join([x + ";" for x in self._current_facts])
2242-
self.respond("200 MLST OPTS " + f)
22432245

22442246
def ftp_NOOP(self, line):
22452247
"""Do nothing."""

0 commit comments

Comments
 (0)