@@ -19,6 +19,8 @@ as mirroring other FTP servers. It is also used by the module
1919:mod: `urllib.request ` to handle URLs that use FTP. For more information on FTP
2020(File Transfer Protocol), see Internet :rfc: `959 `.
2121
22+ The default encoding is UTF-8, following :rfc: `2640 `.
23+
2224Here's a sample session using the :mod: `ftplib ` module::
2325
2426 >>> from ftplib import FTP
@@ -41,7 +43,7 @@ Here's a sample session using the :mod:`ftplib` module::
4143
4244The module defines the following items:
4345
44- .. class :: FTP(host='', user='', passwd='', acct='', timeout=None, source_address=None)
46+ .. class :: FTP(host='', user='', passwd='', acct='', timeout=None, source_address=None, *, encoding='utf-8' )
4547
4648 Return a new instance of the :class: `FTP ` class. When *host * is given, the
4749 method call ``connect(host) `` is made. When *user * is given, additionally
@@ -50,7 +52,8 @@ The module defines the following items:
5052 parameter specifies a timeout in seconds for blocking operations like the
5153 connection attempt (if is not specified, the global default timeout setting
5254 will be used). *source_address * is a 2-tuple ``(host, port) `` for the socket
53- to bind to as its source address before connecting.
55+ to bind to as its source address before connecting. The *encoding * parameter
56+ specifies the encoding for directories and filenames.
5457
5558 The :class: `FTP ` class supports the :keyword: `with ` statement, e.g.:
5659
@@ -74,9 +77,11 @@ The module defines the following items:
7477
7578 .. versionchanged :: 3.9
7679 If the *timeout * parameter is set to be zero, it will raise a
77- :class: `ValueError ` to prevent the creation of a non-blocking socket
80+ :class: `ValueError ` to prevent the creation of a non-blocking socket.
81+ The *encoding * parameter was added, and the default was changed from
82+ Latin-1 to UTF-8 to follow :rfc: `2640 `.
7883
79- .. class :: FTP_TLS(host='', user='', passwd='', acct='', keyfile=None, certfile=None, context=None, timeout=None, source_address=None)
84+ .. class :: FTP_TLS(host='', user='', passwd='', acct='', keyfile=None, certfile=None, context=None, timeout=None, source_address=None, *, encoding='utf-8' )
8085
8186 A :class: `FTP ` subclass which adds TLS support to FTP as described in
8287 :rfc: `4217 `.
@@ -110,7 +115,9 @@ The module defines the following items:
110115
111116 .. versionchanged :: 3.9
112117 If the *timeout * parameter is set to be zero, it will raise a
113- :class: `ValueError ` to prevent the creation of a non-blocking socket
118+ :class: `ValueError ` to prevent the creation of a non-blocking socket.
119+ The *encoding * parameter was added, and the default was changed from
120+ Latin-1 to UTF-8 to follow :rfc: `2640 `.
114121
115122 Here's a sample session using the :class: `FTP_TLS ` class::
116123
@@ -259,9 +266,10 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
259266
260267.. method :: FTP.retrlines(cmd, callback=None)
261268
262- Retrieve a file or directory listing in ASCII transfer mode. *cmd * should be
263- an appropriate ``RETR `` command (see :meth: `retrbinary `) or a command such as
264- ``LIST `` or ``NLST `` (usually just the string ``'LIST' ``).
269+ Retrieve a file or directory listing in the encoding specified by the
270+ *encoding * parameter at initialization.
271+ *cmd * should be an appropriate ``RETR `` command (see :meth: `retrbinary `) or
272+ a command such as ``LIST `` or ``NLST `` (usually just the string ``'LIST' ``).
265273 ``LIST `` retrieves a list of files and information about those files.
266274 ``NLST `` retrieves a list of file names.
267275 The *callback * function is called for each line with a string argument
@@ -291,7 +299,7 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
291299
292300.. method :: FTP.storlines(cmd, fp, callback=None)
293301
294- Store a file in ASCII transfer mode. *cmd * should be an appropriate
302+ Store a file in line mode. *cmd * should be an appropriate
295303 ``STOR `` command (see :meth: `storbinary `). Lines are read until EOF from the
296304 :term: `file object ` *fp * (opened in binary mode) using its :meth: `~io.IOBase.readline `
297305 method to provide the data to be stored. *callback * is an optional single
@@ -309,10 +317,9 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
309317 If optional *rest * is given, a ``REST `` command is sent to the server, passing
310318 *rest * as an argument. *rest * is usually a byte offset into the requested file,
311319 telling the server to restart sending the file's bytes at the requested offset,
312- skipping over the initial bytes. Note however that :rfc: `959 ` requires only that
313- *rest * be a string containing characters in the printable range from ASCII code
314- 33 to ASCII code 126. The :meth: `transfercmd ` method, therefore, converts
315- *rest * to a string, but no check is performed on the string's contents. If the
320+ skipping over the initial bytes. Note however that the :meth: `transfercmd `
321+ method converts *rest * to a string with the *encoding * parameter specified
322+ at initialization, but no check is performed on the string's contents. If the
316323 server does not recognize the ``REST `` command, an :exc: `error_reply ` exception
317324 will be raised. If this happens, simply call :meth: `transfercmd ` without a
318325 *rest * argument.
0 commit comments