feature/ftp-encoding: Improve UTF-8 Support in kio_ftp by Sending CLNT and OPTS UTF8 ON After Login

Problem Statement

The kio_ftp worker (used by Dolphin and other KDE applications for FTP access) currently relies on legacy encodings for decoding filenames and server responses. This leads to garbled or incorrect display of non-ASCII characters (e.g., Cyrillic, Greek, or accented letters) on many modern FTP servers that use UTF-8 by default or require explicit activation.

For example, servers like ftp.galaktika.ru (and similar ones) may require a client identification command (CLNT) before enabling UTF-8 via OPTS UTF8 ON. Without this, users experience issues with filename encoding.

Solution Overview

This MR introduces a simple negotiation mechanism for UTF-8 support in the ftpLogin method of FtpInternal (located in src/kioworkers/ftp/ftp.cpp):

  • After a successful login, send the CLNT kio_ftp command to identify the client (similar to FileZilla's behavior for compatibility with certain servers).
  • Immediately follow with OPTS UTF8 ON to request UTF-8 mode.
  • If the server responds with code 200 (success), call q->remoteEncoding()->setEncoding("UTF-8") to switch all subsequent encoding/decoding operations to UTF-8 via KRemoteEncoding.
  • If the OPTS command fails (e.g., code 500/501/502 for "not supported"), log a debug message and fallback to the default encoding behavior.

Why This Approach?

  • Compatibility and Safety: Sending CLNT first addresses servers that require client identification before OPTS (e.g., some Russian or custom FTP servers). OPTS UTF8 ON is a common non-standard extension (inspired by drafts like draft-ietf-ftpext-utf-8) used by clients like Windows Explorer and Total Commander. If unsupported, servers simply reject it without breaking the session.
  • Minimalism: We initially considered checking FEAT first (per RFC 2640, which mandates "UTF8" in FEAT responses for UTF-8 support). However, parsing multi-line FEAT responses required additional complexity (as ftpResponse only stores the last line, leading to incomplete checks). For this initial MR, we omitted FEAT to keep the patch small and focused—future iterations can add it if needed. This mirrors simplified behaviors in other clients where OPTS is attempted directly.

A search on bugs.kde.org revealed several issues related to FTP encoding in kio_ftp, particularly with UTF-8 and codepages for non-ASCII filenames. The most relevant ones are:

CCBUG: 269370

CCBUG: 165044

Edited by Ramil Nurmanov

Merge request reports

Loading