17db96d56Sopenharmony_ci:mod:`ftplib` --- FTP protocol client 27db96d56Sopenharmony_ci===================================== 37db96d56Sopenharmony_ci 47db96d56Sopenharmony_ci.. module:: ftplib 57db96d56Sopenharmony_ci :synopsis: FTP protocol client (requires sockets). 67db96d56Sopenharmony_ci 77db96d56Sopenharmony_ci**Source code:** :source:`Lib/ftplib.py` 87db96d56Sopenharmony_ci 97db96d56Sopenharmony_ci.. index:: 107db96d56Sopenharmony_ci pair: FTP; protocol 117db96d56Sopenharmony_ci single: FTP; ftplib (standard module) 127db96d56Sopenharmony_ci 137db96d56Sopenharmony_ci-------------- 147db96d56Sopenharmony_ci 157db96d56Sopenharmony_ciThis module defines the class :class:`FTP` and a few related items. The 167db96d56Sopenharmony_ci:class:`FTP` class implements the client side of the FTP protocol. You can use 177db96d56Sopenharmony_cithis to write Python programs that perform a variety of automated FTP jobs, such 187db96d56Sopenharmony_cias mirroring other FTP servers. It is also used by the module 197db96d56Sopenharmony_ci:mod:`urllib.request` to handle URLs that use FTP. For more information on FTP 207db96d56Sopenharmony_ci(File Transfer Protocol), see internet :rfc:`959`. 217db96d56Sopenharmony_ci 227db96d56Sopenharmony_ciThe default encoding is UTF-8, following :rfc:`2640`. 237db96d56Sopenharmony_ci 247db96d56Sopenharmony_ci.. include:: ../includes/wasm-notavail.rst 257db96d56Sopenharmony_ci 267db96d56Sopenharmony_ciHere's a sample session using the :mod:`ftplib` module:: 277db96d56Sopenharmony_ci 287db96d56Sopenharmony_ci >>> from ftplib import FTP 297db96d56Sopenharmony_ci >>> ftp = FTP('ftp.us.debian.org') # connect to host, default port 307db96d56Sopenharmony_ci >>> ftp.login() # user anonymous, passwd anonymous@ 317db96d56Sopenharmony_ci '230 Login successful.' 327db96d56Sopenharmony_ci >>> ftp.cwd('debian') # change into "debian" directory 337db96d56Sopenharmony_ci '250 Directory successfully changed.' 347db96d56Sopenharmony_ci >>> ftp.retrlines('LIST') # list directory contents 357db96d56Sopenharmony_ci -rw-rw-r-- 1 1176 1176 1063 Jun 15 10:18 README 367db96d56Sopenharmony_ci ... 377db96d56Sopenharmony_ci drwxr-sr-x 5 1176 1176 4096 Dec 19 2000 pool 387db96d56Sopenharmony_ci drwxr-sr-x 4 1176 1176 4096 Nov 17 2008 project 397db96d56Sopenharmony_ci drwxr-xr-x 3 1176 1176 4096 Oct 10 2012 tools 407db96d56Sopenharmony_ci '226 Directory send OK.' 417db96d56Sopenharmony_ci >>> with open('README', 'wb') as fp: 427db96d56Sopenharmony_ci >>> ftp.retrbinary('RETR README', fp.write) 437db96d56Sopenharmony_ci '226 Transfer complete.' 447db96d56Sopenharmony_ci >>> ftp.quit() 457db96d56Sopenharmony_ci '221 Goodbye.' 467db96d56Sopenharmony_ci 477db96d56Sopenharmony_ci 487db96d56Sopenharmony_ciThe module defines the following items: 497db96d56Sopenharmony_ci 507db96d56Sopenharmony_ci.. class:: FTP(host='', user='', passwd='', acct='', timeout=None, source_address=None, *, encoding='utf-8') 517db96d56Sopenharmony_ci 527db96d56Sopenharmony_ci Return a new instance of the :class:`FTP` class. When *host* is given, the 537db96d56Sopenharmony_ci method call ``connect(host)`` is made. When *user* is given, additionally 547db96d56Sopenharmony_ci the method call ``login(user, passwd, acct)`` is made (where *passwd* and 557db96d56Sopenharmony_ci *acct* default to the empty string when not given). The optional *timeout* 567db96d56Sopenharmony_ci parameter specifies a timeout in seconds for blocking operations like the 577db96d56Sopenharmony_ci connection attempt (if is not specified, the global default timeout setting 587db96d56Sopenharmony_ci will be used). *source_address* is a 2-tuple ``(host, port)`` for the socket 597db96d56Sopenharmony_ci to bind to as its source address before connecting. The *encoding* parameter 607db96d56Sopenharmony_ci specifies the encoding for directories and filenames. 617db96d56Sopenharmony_ci 627db96d56Sopenharmony_ci The :class:`FTP` class supports the :keyword:`with` statement, e.g.: 637db96d56Sopenharmony_ci 647db96d56Sopenharmony_ci >>> from ftplib import FTP 657db96d56Sopenharmony_ci >>> with FTP("ftp1.at.proftpd.org") as ftp: 667db96d56Sopenharmony_ci ... ftp.login() 677db96d56Sopenharmony_ci ... ftp.dir() 687db96d56Sopenharmony_ci ... # doctest: +SKIP 697db96d56Sopenharmony_ci '230 Anonymous login ok, restrictions apply.' 707db96d56Sopenharmony_ci dr-xr-xr-x 9 ftp ftp 154 May 6 10:43 . 717db96d56Sopenharmony_ci dr-xr-xr-x 9 ftp ftp 154 May 6 10:43 .. 727db96d56Sopenharmony_ci dr-xr-xr-x 5 ftp ftp 4096 May 6 10:43 CentOS 737db96d56Sopenharmony_ci dr-xr-xr-x 3 ftp ftp 18 Jul 10 2008 Fedora 747db96d56Sopenharmony_ci >>> 757db96d56Sopenharmony_ci 767db96d56Sopenharmony_ci .. versionchanged:: 3.2 777db96d56Sopenharmony_ci Support for the :keyword:`with` statement was added. 787db96d56Sopenharmony_ci 797db96d56Sopenharmony_ci .. versionchanged:: 3.3 807db96d56Sopenharmony_ci *source_address* parameter was added. 817db96d56Sopenharmony_ci 827db96d56Sopenharmony_ci .. versionchanged:: 3.9 837db96d56Sopenharmony_ci If the *timeout* parameter is set to be zero, it will raise a 847db96d56Sopenharmony_ci :class:`ValueError` to prevent the creation of a non-blocking socket. 857db96d56Sopenharmony_ci The *encoding* parameter was added, and the default was changed from 867db96d56Sopenharmony_ci Latin-1 to UTF-8 to follow :rfc:`2640`. 877db96d56Sopenharmony_ci 887db96d56Sopenharmony_ci.. class:: FTP_TLS(host='', user='', passwd='', acct='', keyfile=None, certfile=None, context=None, timeout=None, source_address=None, *, encoding='utf-8') 897db96d56Sopenharmony_ci 907db96d56Sopenharmony_ci A :class:`FTP` subclass which adds TLS support to FTP as described in 917db96d56Sopenharmony_ci :rfc:`4217`. 927db96d56Sopenharmony_ci Connect as usual to port 21 implicitly securing the FTP control connection 937db96d56Sopenharmony_ci before authenticating. Securing the data connection requires the user to 947db96d56Sopenharmony_ci explicitly ask for it by calling the :meth:`prot_p` method. *context* 957db96d56Sopenharmony_ci is a :class:`ssl.SSLContext` object which allows bundling SSL configuration 967db96d56Sopenharmony_ci options, certificates and private keys into a single (potentially 977db96d56Sopenharmony_ci long-lived) structure. Please read :ref:`ssl-security` for best practices. 987db96d56Sopenharmony_ci 997db96d56Sopenharmony_ci *keyfile* and *certfile* are a legacy alternative to *context* -- they 1007db96d56Sopenharmony_ci can point to PEM-formatted private key and certificate chain files 1017db96d56Sopenharmony_ci (respectively) for the SSL connection. 1027db96d56Sopenharmony_ci 1037db96d56Sopenharmony_ci .. versionadded:: 3.2 1047db96d56Sopenharmony_ci 1057db96d56Sopenharmony_ci .. versionchanged:: 3.3 1067db96d56Sopenharmony_ci *source_address* parameter was added. 1077db96d56Sopenharmony_ci 1087db96d56Sopenharmony_ci .. versionchanged:: 3.4 1097db96d56Sopenharmony_ci The class now supports hostname check with 1107db96d56Sopenharmony_ci :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see 1117db96d56Sopenharmony_ci :data:`ssl.HAS_SNI`). 1127db96d56Sopenharmony_ci 1137db96d56Sopenharmony_ci .. deprecated:: 3.6 1147db96d56Sopenharmony_ci 1157db96d56Sopenharmony_ci *keyfile* and *certfile* are deprecated in favor of *context*. 1167db96d56Sopenharmony_ci Please use :meth:`ssl.SSLContext.load_cert_chain` instead, or let 1177db96d56Sopenharmony_ci :func:`ssl.create_default_context` select the system's trusted CA 1187db96d56Sopenharmony_ci certificates for you. 1197db96d56Sopenharmony_ci 1207db96d56Sopenharmony_ci .. versionchanged:: 3.9 1217db96d56Sopenharmony_ci If the *timeout* parameter is set to be zero, it will raise a 1227db96d56Sopenharmony_ci :class:`ValueError` to prevent the creation of a non-blocking socket. 1237db96d56Sopenharmony_ci The *encoding* parameter was added, and the default was changed from 1247db96d56Sopenharmony_ci Latin-1 to UTF-8 to follow :rfc:`2640`. 1257db96d56Sopenharmony_ci 1267db96d56Sopenharmony_ci Here's a sample session using the :class:`FTP_TLS` class:: 1277db96d56Sopenharmony_ci 1287db96d56Sopenharmony_ci >>> ftps = FTP_TLS('ftp.pureftpd.org') 1297db96d56Sopenharmony_ci >>> ftps.login() 1307db96d56Sopenharmony_ci '230 Anonymous user logged in' 1317db96d56Sopenharmony_ci >>> ftps.prot_p() 1327db96d56Sopenharmony_ci '200 Data protection level set to "private"' 1337db96d56Sopenharmony_ci >>> ftps.nlst() 1347db96d56Sopenharmony_ci ['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'] 1357db96d56Sopenharmony_ci 1367db96d56Sopenharmony_ci 1377db96d56Sopenharmony_ci.. exception:: error_reply 1387db96d56Sopenharmony_ci 1397db96d56Sopenharmony_ci Exception raised when an unexpected reply is received from the server. 1407db96d56Sopenharmony_ci 1417db96d56Sopenharmony_ci 1427db96d56Sopenharmony_ci.. exception:: error_temp 1437db96d56Sopenharmony_ci 1447db96d56Sopenharmony_ci Exception raised when an error code signifying a temporary error (response 1457db96d56Sopenharmony_ci codes in the range 400--499) is received. 1467db96d56Sopenharmony_ci 1477db96d56Sopenharmony_ci 1487db96d56Sopenharmony_ci.. exception:: error_perm 1497db96d56Sopenharmony_ci 1507db96d56Sopenharmony_ci Exception raised when an error code signifying a permanent error (response 1517db96d56Sopenharmony_ci codes in the range 500--599) is received. 1527db96d56Sopenharmony_ci 1537db96d56Sopenharmony_ci 1547db96d56Sopenharmony_ci.. exception:: error_proto 1557db96d56Sopenharmony_ci 1567db96d56Sopenharmony_ci Exception raised when a reply is received from the server that does not fit 1577db96d56Sopenharmony_ci the response specifications of the File Transfer Protocol, i.e. begin with a 1587db96d56Sopenharmony_ci digit in the range 1--5. 1597db96d56Sopenharmony_ci 1607db96d56Sopenharmony_ci 1617db96d56Sopenharmony_ci.. data:: all_errors 1627db96d56Sopenharmony_ci 1637db96d56Sopenharmony_ci The set of all exceptions (as a tuple) that methods of :class:`FTP` 1647db96d56Sopenharmony_ci instances may raise as a result of problems with the FTP connection (as 1657db96d56Sopenharmony_ci opposed to programming errors made by the caller). This set includes the 1667db96d56Sopenharmony_ci four exceptions listed above as well as :exc:`OSError` and :exc:`EOFError`. 1677db96d56Sopenharmony_ci 1687db96d56Sopenharmony_ci 1697db96d56Sopenharmony_ci.. seealso:: 1707db96d56Sopenharmony_ci 1717db96d56Sopenharmony_ci Module :mod:`netrc` 1727db96d56Sopenharmony_ci Parser for the :file:`.netrc` file format. The file :file:`.netrc` is 1737db96d56Sopenharmony_ci typically used by FTP clients to load user authentication information 1747db96d56Sopenharmony_ci before prompting the user. 1757db96d56Sopenharmony_ci 1767db96d56Sopenharmony_ci 1777db96d56Sopenharmony_ci.. _ftp-objects: 1787db96d56Sopenharmony_ci 1797db96d56Sopenharmony_ciFTP Objects 1807db96d56Sopenharmony_ci----------- 1817db96d56Sopenharmony_ci 1827db96d56Sopenharmony_ciSeveral methods are available in two flavors: one for handling text files and 1837db96d56Sopenharmony_cianother for binary files. These are named for the command which is used 1847db96d56Sopenharmony_cifollowed by ``lines`` for the text version or ``binary`` for the binary version. 1857db96d56Sopenharmony_ci 1867db96d56Sopenharmony_ci:class:`FTP` instances have the following methods: 1877db96d56Sopenharmony_ci 1887db96d56Sopenharmony_ci 1897db96d56Sopenharmony_ci.. method:: FTP.set_debuglevel(level) 1907db96d56Sopenharmony_ci 1917db96d56Sopenharmony_ci Set the instance's debugging level. This controls the amount of debugging 1927db96d56Sopenharmony_ci output printed. The default, ``0``, produces no debugging output. A value of 1937db96d56Sopenharmony_ci ``1`` produces a moderate amount of debugging output, generally a single line 1947db96d56Sopenharmony_ci per request. A value of ``2`` or higher produces the maximum amount of 1957db96d56Sopenharmony_ci debugging output, logging each line sent and received on the control connection. 1967db96d56Sopenharmony_ci 1977db96d56Sopenharmony_ci 1987db96d56Sopenharmony_ci.. method:: FTP.connect(host='', port=0, timeout=None, source_address=None) 1997db96d56Sopenharmony_ci 2007db96d56Sopenharmony_ci Connect to the given host and port. The default port number is ``21``, as 2017db96d56Sopenharmony_ci specified by the FTP protocol specification. It is rarely needed to specify a 2027db96d56Sopenharmony_ci different port number. This function should be called only once for each 2037db96d56Sopenharmony_ci instance; it should not be called at all if a host was given when the instance 2047db96d56Sopenharmony_ci was created. All other methods can only be used after a connection has been 2057db96d56Sopenharmony_ci made. 2067db96d56Sopenharmony_ci The optional *timeout* parameter specifies a timeout in seconds for the 2077db96d56Sopenharmony_ci connection attempt. If no *timeout* is passed, the global default timeout 2087db96d56Sopenharmony_ci setting will be used. 2097db96d56Sopenharmony_ci *source_address* is a 2-tuple ``(host, port)`` for the socket to bind to as 2107db96d56Sopenharmony_ci its source address before connecting. 2117db96d56Sopenharmony_ci 2127db96d56Sopenharmony_ci .. audit-event:: ftplib.connect self,host,port ftplib.FTP.connect 2137db96d56Sopenharmony_ci 2147db96d56Sopenharmony_ci .. versionchanged:: 3.3 2157db96d56Sopenharmony_ci *source_address* parameter was added. 2167db96d56Sopenharmony_ci 2177db96d56Sopenharmony_ci 2187db96d56Sopenharmony_ci.. method:: FTP.getwelcome() 2197db96d56Sopenharmony_ci 2207db96d56Sopenharmony_ci Return the welcome message sent by the server in reply to the initial 2217db96d56Sopenharmony_ci connection. (This message sometimes contains disclaimers or help information 2227db96d56Sopenharmony_ci that may be relevant to the user.) 2237db96d56Sopenharmony_ci 2247db96d56Sopenharmony_ci 2257db96d56Sopenharmony_ci.. method:: FTP.login(user='anonymous', passwd='', acct='') 2267db96d56Sopenharmony_ci 2277db96d56Sopenharmony_ci Log in as the given *user*. The *passwd* and *acct* parameters are optional and 2287db96d56Sopenharmony_ci default to the empty string. If no *user* is specified, it defaults to 2297db96d56Sopenharmony_ci ``'anonymous'``. If *user* is ``'anonymous'``, the default *passwd* is 2307db96d56Sopenharmony_ci ``'anonymous@'``. This function should be called only once for each instance, 2317db96d56Sopenharmony_ci after a connection has been established; it should not be called at all if a 2327db96d56Sopenharmony_ci host and user were given when the instance was created. Most FTP commands are 2337db96d56Sopenharmony_ci only allowed after the client has logged in. The *acct* parameter supplies 2347db96d56Sopenharmony_ci "accounting information"; few systems implement this. 2357db96d56Sopenharmony_ci 2367db96d56Sopenharmony_ci 2377db96d56Sopenharmony_ci.. method:: FTP.abort() 2387db96d56Sopenharmony_ci 2397db96d56Sopenharmony_ci Abort a file transfer that is in progress. Using this does not always work, but 2407db96d56Sopenharmony_ci it's worth a try. 2417db96d56Sopenharmony_ci 2427db96d56Sopenharmony_ci 2437db96d56Sopenharmony_ci.. method:: FTP.sendcmd(cmd) 2447db96d56Sopenharmony_ci 2457db96d56Sopenharmony_ci Send a simple command string to the server and return the response string. 2467db96d56Sopenharmony_ci 2477db96d56Sopenharmony_ci .. audit-event:: ftplib.sendcmd self,cmd ftplib.FTP.sendcmd 2487db96d56Sopenharmony_ci 2497db96d56Sopenharmony_ci 2507db96d56Sopenharmony_ci.. method:: FTP.voidcmd(cmd) 2517db96d56Sopenharmony_ci 2527db96d56Sopenharmony_ci Send a simple command string to the server and handle the response. Return 2537db96d56Sopenharmony_ci nothing if a response code corresponding to success (codes in the range 2547db96d56Sopenharmony_ci 200--299) is received. Raise :exc:`error_reply` otherwise. 2557db96d56Sopenharmony_ci 2567db96d56Sopenharmony_ci .. audit-event:: ftplib.sendcmd self,cmd ftplib.FTP.voidcmd 2577db96d56Sopenharmony_ci 2587db96d56Sopenharmony_ci 2597db96d56Sopenharmony_ci.. method:: FTP.retrbinary(cmd, callback, blocksize=8192, rest=None) 2607db96d56Sopenharmony_ci 2617db96d56Sopenharmony_ci Retrieve a file in binary transfer mode. *cmd* should be an appropriate 2627db96d56Sopenharmony_ci ``RETR`` command: ``'RETR filename'``. The *callback* function is called for 2637db96d56Sopenharmony_ci each block of data received, with a single bytes argument giving the data 2647db96d56Sopenharmony_ci block. The optional *blocksize* argument specifies the maximum chunk size to 2657db96d56Sopenharmony_ci read on the low-level socket object created to do the actual transfer (which 2667db96d56Sopenharmony_ci will also be the largest size of the data blocks passed to *callback*). A 2677db96d56Sopenharmony_ci reasonable default is chosen. *rest* means the same thing as in the 2687db96d56Sopenharmony_ci :meth:`transfercmd` method. 2697db96d56Sopenharmony_ci 2707db96d56Sopenharmony_ci 2717db96d56Sopenharmony_ci.. method:: FTP.retrlines(cmd, callback=None) 2727db96d56Sopenharmony_ci 2737db96d56Sopenharmony_ci Retrieve a file or directory listing in the encoding specified by the 2747db96d56Sopenharmony_ci *encoding* parameter at initialization. 2757db96d56Sopenharmony_ci *cmd* should be an appropriate ``RETR`` command (see :meth:`retrbinary`) or 2767db96d56Sopenharmony_ci a command such as ``LIST`` or ``NLST`` (usually just the string ``'LIST'``). 2777db96d56Sopenharmony_ci ``LIST`` retrieves a list of files and information about those files. 2787db96d56Sopenharmony_ci ``NLST`` retrieves a list of file names. 2797db96d56Sopenharmony_ci The *callback* function is called for each line with a string argument 2807db96d56Sopenharmony_ci containing the line with the trailing CRLF stripped. The default *callback* 2817db96d56Sopenharmony_ci prints the line to ``sys.stdout``. 2827db96d56Sopenharmony_ci 2837db96d56Sopenharmony_ci 2847db96d56Sopenharmony_ci.. method:: FTP.set_pasv(val) 2857db96d56Sopenharmony_ci 2867db96d56Sopenharmony_ci Enable "passive" mode if *val* is true, otherwise disable passive mode. 2877db96d56Sopenharmony_ci Passive mode is on by default. 2887db96d56Sopenharmony_ci 2897db96d56Sopenharmony_ci 2907db96d56Sopenharmony_ci.. method:: FTP.storbinary(cmd, fp, blocksize=8192, callback=None, rest=None) 2917db96d56Sopenharmony_ci 2927db96d56Sopenharmony_ci Store a file in binary transfer mode. *cmd* should be an appropriate 2937db96d56Sopenharmony_ci ``STOR`` command: ``"STOR filename"``. *fp* is a :term:`file object` 2947db96d56Sopenharmony_ci (opened in binary mode) which is read until EOF using its :meth:`~io.IOBase.read` 2957db96d56Sopenharmony_ci method in blocks of size *blocksize* to provide the data to be stored. 2967db96d56Sopenharmony_ci The *blocksize* argument defaults to 8192. *callback* is an optional single 2977db96d56Sopenharmony_ci parameter callable that is called on each block of data after it is sent. 2987db96d56Sopenharmony_ci *rest* means the same thing as in the :meth:`transfercmd` method. 2997db96d56Sopenharmony_ci 3007db96d56Sopenharmony_ci .. versionchanged:: 3.2 3017db96d56Sopenharmony_ci *rest* parameter added. 3027db96d56Sopenharmony_ci 3037db96d56Sopenharmony_ci 3047db96d56Sopenharmony_ci.. method:: FTP.storlines(cmd, fp, callback=None) 3057db96d56Sopenharmony_ci 3067db96d56Sopenharmony_ci Store a file in line mode. *cmd* should be an appropriate 3077db96d56Sopenharmony_ci ``STOR`` command (see :meth:`storbinary`). Lines are read until EOF from the 3087db96d56Sopenharmony_ci :term:`file object` *fp* (opened in binary mode) using its :meth:`~io.IOBase.readline` 3097db96d56Sopenharmony_ci method to provide the data to be stored. *callback* is an optional single 3107db96d56Sopenharmony_ci parameter callable that is called on each line after it is sent. 3117db96d56Sopenharmony_ci 3127db96d56Sopenharmony_ci 3137db96d56Sopenharmony_ci.. method:: FTP.transfercmd(cmd, rest=None) 3147db96d56Sopenharmony_ci 3157db96d56Sopenharmony_ci Initiate a transfer over the data connection. If the transfer is active, send an 3167db96d56Sopenharmony_ci ``EPRT`` or ``PORT`` command and the transfer command specified by *cmd*, and 3177db96d56Sopenharmony_ci accept the connection. If the server is passive, send an ``EPSV`` or ``PASV`` 3187db96d56Sopenharmony_ci command, connect to it, and start the transfer command. Either way, return the 3197db96d56Sopenharmony_ci socket for the connection. 3207db96d56Sopenharmony_ci 3217db96d56Sopenharmony_ci If optional *rest* is given, a ``REST`` command is sent to the server, passing 3227db96d56Sopenharmony_ci *rest* as an argument. *rest* is usually a byte offset into the requested file, 3237db96d56Sopenharmony_ci telling the server to restart sending the file's bytes at the requested offset, 3247db96d56Sopenharmony_ci skipping over the initial bytes. Note however that the :meth:`transfercmd` 3257db96d56Sopenharmony_ci method converts *rest* to a string with the *encoding* parameter specified 3267db96d56Sopenharmony_ci at initialization, but no check is performed on the string's contents. If the 3277db96d56Sopenharmony_ci server does not recognize the ``REST`` command, an :exc:`error_reply` exception 3287db96d56Sopenharmony_ci will be raised. If this happens, simply call :meth:`transfercmd` without a 3297db96d56Sopenharmony_ci *rest* argument. 3307db96d56Sopenharmony_ci 3317db96d56Sopenharmony_ci 3327db96d56Sopenharmony_ci.. method:: FTP.ntransfercmd(cmd, rest=None) 3337db96d56Sopenharmony_ci 3347db96d56Sopenharmony_ci Like :meth:`transfercmd`, but returns a tuple of the data connection and the 3357db96d56Sopenharmony_ci expected size of the data. If the expected size could not be computed, ``None`` 3367db96d56Sopenharmony_ci will be returned as the expected size. *cmd* and *rest* means the same thing as 3377db96d56Sopenharmony_ci in :meth:`transfercmd`. 3387db96d56Sopenharmony_ci 3397db96d56Sopenharmony_ci 3407db96d56Sopenharmony_ci.. method:: FTP.mlsd(path="", facts=[]) 3417db96d56Sopenharmony_ci 3427db96d56Sopenharmony_ci List a directory in a standardized format by using ``MLSD`` command 3437db96d56Sopenharmony_ci (:rfc:`3659`). If *path* is omitted the current directory is assumed. 3447db96d56Sopenharmony_ci *facts* is a list of strings representing the type of information desired 3457db96d56Sopenharmony_ci (e.g. ``["type", "size", "perm"]``). Return a generator object yielding a 3467db96d56Sopenharmony_ci tuple of two elements for every file found in path. First element is the 3477db96d56Sopenharmony_ci file name, the second one is a dictionary containing facts about the file 3487db96d56Sopenharmony_ci name. Content of this dictionary might be limited by the *facts* argument 3497db96d56Sopenharmony_ci but server is not guaranteed to return all requested facts. 3507db96d56Sopenharmony_ci 3517db96d56Sopenharmony_ci .. versionadded:: 3.3 3527db96d56Sopenharmony_ci 3537db96d56Sopenharmony_ci 3547db96d56Sopenharmony_ci.. method:: FTP.nlst(argument[, ...]) 3557db96d56Sopenharmony_ci 3567db96d56Sopenharmony_ci Return a list of file names as returned by the ``NLST`` command. The 3577db96d56Sopenharmony_ci optional *argument* is a directory to list (default is the current server 3587db96d56Sopenharmony_ci directory). Multiple arguments can be used to pass non-standard options to 3597db96d56Sopenharmony_ci the ``NLST`` command. 3607db96d56Sopenharmony_ci 3617db96d56Sopenharmony_ci .. note:: If your server supports the command, :meth:`mlsd` offers a better API. 3627db96d56Sopenharmony_ci 3637db96d56Sopenharmony_ci 3647db96d56Sopenharmony_ci.. method:: FTP.dir(argument[, ...]) 3657db96d56Sopenharmony_ci 3667db96d56Sopenharmony_ci Produce a directory listing as returned by the ``LIST`` command, printing it to 3677db96d56Sopenharmony_ci standard output. The optional *argument* is a directory to list (default is the 3687db96d56Sopenharmony_ci current server directory). Multiple arguments can be used to pass non-standard 3697db96d56Sopenharmony_ci options to the ``LIST`` command. If the last argument is a function, it is used 3707db96d56Sopenharmony_ci as a *callback* function as for :meth:`retrlines`; the default prints to 3717db96d56Sopenharmony_ci ``sys.stdout``. This method returns ``None``. 3727db96d56Sopenharmony_ci 3737db96d56Sopenharmony_ci .. note:: If your server supports the command, :meth:`mlsd` offers a better API. 3747db96d56Sopenharmony_ci 3757db96d56Sopenharmony_ci 3767db96d56Sopenharmony_ci.. method:: FTP.rename(fromname, toname) 3777db96d56Sopenharmony_ci 3787db96d56Sopenharmony_ci Rename file *fromname* on the server to *toname*. 3797db96d56Sopenharmony_ci 3807db96d56Sopenharmony_ci 3817db96d56Sopenharmony_ci.. method:: FTP.delete(filename) 3827db96d56Sopenharmony_ci 3837db96d56Sopenharmony_ci Remove the file named *filename* from the server. If successful, returns the 3847db96d56Sopenharmony_ci text of the response, otherwise raises :exc:`error_perm` on permission errors or 3857db96d56Sopenharmony_ci :exc:`error_reply` on other errors. 3867db96d56Sopenharmony_ci 3877db96d56Sopenharmony_ci 3887db96d56Sopenharmony_ci.. method:: FTP.cwd(pathname) 3897db96d56Sopenharmony_ci 3907db96d56Sopenharmony_ci Set the current directory on the server. 3917db96d56Sopenharmony_ci 3927db96d56Sopenharmony_ci 3937db96d56Sopenharmony_ci.. method:: FTP.mkd(pathname) 3947db96d56Sopenharmony_ci 3957db96d56Sopenharmony_ci Create a new directory on the server. 3967db96d56Sopenharmony_ci 3977db96d56Sopenharmony_ci 3987db96d56Sopenharmony_ci.. method:: FTP.pwd() 3997db96d56Sopenharmony_ci 4007db96d56Sopenharmony_ci Return the pathname of the current directory on the server. 4017db96d56Sopenharmony_ci 4027db96d56Sopenharmony_ci 4037db96d56Sopenharmony_ci.. method:: FTP.rmd(dirname) 4047db96d56Sopenharmony_ci 4057db96d56Sopenharmony_ci Remove the directory named *dirname* on the server. 4067db96d56Sopenharmony_ci 4077db96d56Sopenharmony_ci 4087db96d56Sopenharmony_ci.. method:: FTP.size(filename) 4097db96d56Sopenharmony_ci 4107db96d56Sopenharmony_ci Request the size of the file named *filename* on the server. On success, the 4117db96d56Sopenharmony_ci size of the file is returned as an integer, otherwise ``None`` is returned. 4127db96d56Sopenharmony_ci Note that the ``SIZE`` command is not standardized, but is supported by many 4137db96d56Sopenharmony_ci common server implementations. 4147db96d56Sopenharmony_ci 4157db96d56Sopenharmony_ci 4167db96d56Sopenharmony_ci.. method:: FTP.quit() 4177db96d56Sopenharmony_ci 4187db96d56Sopenharmony_ci Send a ``QUIT`` command to the server and close the connection. This is the 4197db96d56Sopenharmony_ci "polite" way to close a connection, but it may raise an exception if the server 4207db96d56Sopenharmony_ci responds with an error to the ``QUIT`` command. This implies a call to the 4217db96d56Sopenharmony_ci :meth:`close` method which renders the :class:`FTP` instance useless for 4227db96d56Sopenharmony_ci subsequent calls (see below). 4237db96d56Sopenharmony_ci 4247db96d56Sopenharmony_ci 4257db96d56Sopenharmony_ci.. method:: FTP.close() 4267db96d56Sopenharmony_ci 4277db96d56Sopenharmony_ci Close the connection unilaterally. This should not be applied to an already 4287db96d56Sopenharmony_ci closed connection such as after a successful call to :meth:`~FTP.quit`. 4297db96d56Sopenharmony_ci After this call the :class:`FTP` instance should not be used any more (after 4307db96d56Sopenharmony_ci a call to :meth:`close` or :meth:`~FTP.quit` you cannot reopen the 4317db96d56Sopenharmony_ci connection by issuing another :meth:`login` method). 4327db96d56Sopenharmony_ci 4337db96d56Sopenharmony_ci 4347db96d56Sopenharmony_ciFTP_TLS Objects 4357db96d56Sopenharmony_ci--------------- 4367db96d56Sopenharmony_ci 4377db96d56Sopenharmony_ci:class:`FTP_TLS` class inherits from :class:`FTP`, defining these additional objects: 4387db96d56Sopenharmony_ci 4397db96d56Sopenharmony_ci.. attribute:: FTP_TLS.ssl_version 4407db96d56Sopenharmony_ci 4417db96d56Sopenharmony_ci The SSL version to use (defaults to :attr:`ssl.PROTOCOL_SSLv23`). 4427db96d56Sopenharmony_ci 4437db96d56Sopenharmony_ci.. method:: FTP_TLS.auth() 4447db96d56Sopenharmony_ci 4457db96d56Sopenharmony_ci Set up a secure control connection by using TLS or SSL, depending on what 4467db96d56Sopenharmony_ci is specified in the :attr:`ssl_version` attribute. 4477db96d56Sopenharmony_ci 4487db96d56Sopenharmony_ci .. versionchanged:: 3.4 4497db96d56Sopenharmony_ci The method now supports hostname check with 4507db96d56Sopenharmony_ci :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see 4517db96d56Sopenharmony_ci :data:`ssl.HAS_SNI`). 4527db96d56Sopenharmony_ci 4537db96d56Sopenharmony_ci.. method:: FTP_TLS.ccc() 4547db96d56Sopenharmony_ci 4557db96d56Sopenharmony_ci Revert control channel back to plaintext. This can be useful to take 4567db96d56Sopenharmony_ci advantage of firewalls that know how to handle NAT with non-secure FTP 4577db96d56Sopenharmony_ci without opening fixed ports. 4587db96d56Sopenharmony_ci 4597db96d56Sopenharmony_ci .. versionadded:: 3.3 4607db96d56Sopenharmony_ci 4617db96d56Sopenharmony_ci.. method:: FTP_TLS.prot_p() 4627db96d56Sopenharmony_ci 4637db96d56Sopenharmony_ci Set up secure data connection. 4647db96d56Sopenharmony_ci 4657db96d56Sopenharmony_ci.. method:: FTP_TLS.prot_c() 4667db96d56Sopenharmony_ci 4677db96d56Sopenharmony_ci Set up clear text data connection. 468