mirror of
https://github.com/python/cpython.git
synced 2025-07-26 12:44:33 +00:00
Docs: structure the ftplib reference (#114317)
Introduce the following headings and subheadings: - Reference * FTP objects * FTP_TLS objects * Module variables
This commit is contained in:
parent
e6495159f6
commit
b1ad5a5d44
1 changed files with 300 additions and 294 deletions
|
@ -45,7 +45,15 @@ Here's a sample session using the :mod:`ftplib` module::
|
|||
'221 Goodbye.'
|
||||
|
||||
|
||||
The module defines the following items:
|
||||
.. _ftplib-reference:
|
||||
|
||||
Reference
|
||||
---------
|
||||
|
||||
.. _ftp-objects:
|
||||
|
||||
FTP objects
|
||||
^^^^^^^^^^^
|
||||
|
||||
.. class:: FTP(host='', user='', passwd='', acct='', timeout=None, source_address=None, *, encoding='utf-8')
|
||||
|
||||
|
@ -85,100 +93,13 @@ The module defines the following items:
|
|||
The *encoding* parameter was added, and the default was changed from
|
||||
Latin-1 to UTF-8 to follow :rfc:`2640`.
|
||||
|
||||
.. class:: FTP_TLS(host='', user='', passwd='', acct='', *, context=None,
|
||||
timeout=None, source_address=None, encoding='utf-8')
|
||||
|
||||
A :class:`FTP` subclass which adds TLS support to FTP as described in
|
||||
:rfc:`4217`.
|
||||
Connect as usual to port 21 implicitly securing the FTP control connection
|
||||
before authenticating. Securing the data connection requires the user to
|
||||
explicitly ask for it by calling the :meth:`prot_p` method. *context*
|
||||
is a :class:`ssl.SSLContext` object which allows bundling SSL configuration
|
||||
options, certificates and private keys into a single (potentially
|
||||
long-lived) structure. Please read :ref:`ssl-security` for best practices.
|
||||
|
||||
.. versionadded:: 3.2
|
||||
|
||||
.. versionchanged:: 3.3
|
||||
*source_address* parameter was added.
|
||||
|
||||
.. versionchanged:: 3.4
|
||||
The class now supports hostname check with
|
||||
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
|
||||
:const:`ssl.HAS_SNI`).
|
||||
|
||||
.. versionchanged:: 3.9
|
||||
If the *timeout* parameter is set to be zero, it will raise a
|
||||
:class:`ValueError` to prevent the creation of a non-blocking socket.
|
||||
The *encoding* parameter was added, and the default was changed from
|
||||
Latin-1 to UTF-8 to follow :rfc:`2640`.
|
||||
|
||||
.. versionchanged:: 3.12
|
||||
The deprecated *keyfile* and *certfile* parameters have been removed.
|
||||
|
||||
Here's a sample session using the :class:`FTP_TLS` class::
|
||||
|
||||
>>> ftps = FTP_TLS('ftp.pureftpd.org')
|
||||
>>> ftps.login()
|
||||
'230 Anonymous user logged in'
|
||||
>>> ftps.prot_p()
|
||||
'200 Data protection level set to "private"'
|
||||
>>> ftps.nlst()
|
||||
['6jack', 'OpenBSD', 'antilink', 'blogbench', 'bsdcam', 'clockspeed', 'djbdns-jedi', 'docs', 'eaccelerator-jedi', 'favicon.ico', 'francotone', 'fugu', 'ignore', 'libpuzzle', 'metalog', 'minidentd', 'misc', 'mysql-udf-global-user-variables', 'php-jenkins-hash', 'php-skein-hash', 'php-webdav', 'phpaudit', 'phpbench', 'pincaster', 'ping', 'posto', 'pub', 'public', 'public_keys', 'pure-ftpd', 'qscan', 'qtc', 'sharedance', 'skycache', 'sound', 'tmp', 'ucarp']
|
||||
|
||||
|
||||
.. exception:: error_reply
|
||||
|
||||
Exception raised when an unexpected reply is received from the server.
|
||||
|
||||
|
||||
.. exception:: error_temp
|
||||
|
||||
Exception raised when an error code signifying a temporary error (response
|
||||
codes in the range 400--499) is received.
|
||||
|
||||
|
||||
.. exception:: error_perm
|
||||
|
||||
Exception raised when an error code signifying a permanent error (response
|
||||
codes in the range 500--599) is received.
|
||||
|
||||
|
||||
.. exception:: error_proto
|
||||
|
||||
Exception raised when a reply is received from the server that does not fit
|
||||
the response specifications of the File Transfer Protocol, i.e. begin with a
|
||||
digit in the range 1--5.
|
||||
|
||||
|
||||
.. data:: all_errors
|
||||
|
||||
The set of all exceptions (as a tuple) that methods of :class:`FTP`
|
||||
instances may raise as a result of problems with the FTP connection (as
|
||||
opposed to programming errors made by the caller). This set includes the
|
||||
four exceptions listed above as well as :exc:`OSError` and :exc:`EOFError`.
|
||||
|
||||
|
||||
.. seealso::
|
||||
|
||||
Module :mod:`netrc`
|
||||
Parser for the :file:`.netrc` file format. The file :file:`.netrc` is
|
||||
typically used by FTP clients to load user authentication information
|
||||
before prompting the user.
|
||||
|
||||
|
||||
.. _ftp-objects:
|
||||
|
||||
FTP Objects
|
||||
-----------
|
||||
|
||||
Several methods are available in two flavors: one for handling text files and
|
||||
another for binary files. These are named for the command which is used
|
||||
followed by ``lines`` for the text version or ``binary`` for the binary version.
|
||||
Several :class:`!FTP` methods are available in two flavors:
|
||||
one for handling text files and another for binary files.
|
||||
The methods are named for the command which is used followed by
|
||||
``lines`` for the text version or ``binary`` for the binary version.
|
||||
|
||||
:class:`FTP` instances have the following methods:
|
||||
|
||||
|
||||
.. method:: FTP.set_debuglevel(level)
|
||||
|
||||
Set the instance's debugging level. This controls the amount of debugging
|
||||
|
@ -424,10 +345,52 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
|
|||
connection by issuing another :meth:`login` method).
|
||||
|
||||
|
||||
FTP_TLS Objects
|
||||
---------------
|
||||
FTP_TLS objects
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
:class:`FTP_TLS` class inherits from :class:`FTP`, defining these additional objects:
|
||||
.. class:: FTP_TLS(host='', user='', passwd='', acct='', *, context=None,
|
||||
timeout=None, source_address=None, encoding='utf-8')
|
||||
|
||||
A :class:`FTP` subclass which adds TLS support to FTP as described in
|
||||
:rfc:`4217`.
|
||||
Connect as usual to port 21 implicitly securing the FTP control connection
|
||||
before authenticating. Securing the data connection requires the user to
|
||||
explicitly ask for it by calling the :meth:`prot_p` method. *context*
|
||||
is a :class:`ssl.SSLContext` object which allows bundling SSL configuration
|
||||
options, certificates and private keys into a single (potentially
|
||||
long-lived) structure. Please read :ref:`ssl-security` for best practices.
|
||||
|
||||
.. versionadded:: 3.2
|
||||
|
||||
.. versionchanged:: 3.3
|
||||
*source_address* parameter was added.
|
||||
|
||||
.. versionchanged:: 3.4
|
||||
The class now supports hostname check with
|
||||
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
|
||||
:const:`ssl.HAS_SNI`).
|
||||
|
||||
.. versionchanged:: 3.9
|
||||
If the *timeout* parameter is set to be zero, it will raise a
|
||||
:class:`ValueError` to prevent the creation of a non-blocking socket.
|
||||
The *encoding* parameter was added, and the default was changed from
|
||||
Latin-1 to UTF-8 to follow :rfc:`2640`.
|
||||
|
||||
.. versionchanged:: 3.12
|
||||
The deprecated *keyfile* and *certfile* parameters have been removed.
|
||||
|
||||
Here's a sample session using the :class:`FTP_TLS` class::
|
||||
|
||||
>>> ftps = FTP_TLS('ftp.pureftpd.org')
|
||||
>>> ftps.login()
|
||||
'230 Anonymous user logged in'
|
||||
>>> ftps.prot_p()
|
||||
'200 Data protection level set to "private"'
|
||||
>>> ftps.nlst()
|
||||
['6jack', 'OpenBSD', 'antilink', 'blogbench', 'bsdcam', 'clockspeed', 'djbdns-jedi', 'docs', 'eaccelerator-jedi', 'favicon.ico', 'francotone', 'fugu', 'ignore', 'libpuzzle', 'metalog', 'minidentd', 'misc', 'mysql-udf-global-user-variables', 'php-jenkins-hash', 'php-skein-hash', 'php-webdav', 'phpaudit', 'phpbench', 'pincaster', 'ping', 'posto', 'pub', 'public', 'public_keys', 'pure-ftpd', 'qscan', 'qtc', 'sharedance', 'skycache', 'sound', 'tmp', 'ucarp']
|
||||
|
||||
:class:`!FTP_TLS` class inherits from :class:`FTP`,
|
||||
defining these additional methods and attributes:
|
||||
|
||||
.. attribute:: FTP_TLS.ssl_version
|
||||
|
||||
|
@ -458,3 +421,46 @@ FTP_TLS Objects
|
|||
.. method:: FTP_TLS.prot_c()
|
||||
|
||||
Set up clear text data connection.
|
||||
|
||||
|
||||
Module variables
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
.. exception:: error_reply
|
||||
|
||||
Exception raised when an unexpected reply is received from the server.
|
||||
|
||||
|
||||
.. exception:: error_temp
|
||||
|
||||
Exception raised when an error code signifying a temporary error (response
|
||||
codes in the range 400--499) is received.
|
||||
|
||||
|
||||
.. exception:: error_perm
|
||||
|
||||
Exception raised when an error code signifying a permanent error (response
|
||||
codes in the range 500--599) is received.
|
||||
|
||||
|
||||
.. exception:: error_proto
|
||||
|
||||
Exception raised when a reply is received from the server that does not fit
|
||||
the response specifications of the File Transfer Protocol, i.e. begin with a
|
||||
digit in the range 1--5.
|
||||
|
||||
|
||||
.. data:: all_errors
|
||||
|
||||
The set of all exceptions (as a tuple) that methods of :class:`FTP`
|
||||
instances may raise as a result of problems with the FTP connection (as
|
||||
opposed to programming errors made by the caller). This set includes the
|
||||
four exceptions listed above as well as :exc:`OSError` and :exc:`EOFError`.
|
||||
|
||||
|
||||
.. seealso::
|
||||
|
||||
Module :mod:`netrc`
|
||||
Parser for the :file:`.netrc` file format. The file :file:`.netrc` is
|
||||
typically used by FTP clients to load user authentication information
|
||||
before prompting the user.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue