ftplib
— FTP (文件传输协议) 客户端
¶
源代码: Lib/ftplib.py
此模块定义类
FTP
和一些相关项。
FTP
类实现 FTP 协议的客户端侧。可以使用这编写 Python 程序履行各种自动 FTP 作业 (譬如:镜像其它 FTP 服务器)。它还可用于模块
urllib.request
to handle URLs that use FTP. For more information on FTP (File Transfer Protocol), see internet
RFC 959
.
默认编码为 UTF-8,遵循 RFC 2640 .
可用性 :非 WASI。
This module does not work or is not available on WebAssembly. See WebAssembly 平台 了解更多信息。
这里的样本会话使用
ftplib
模块:
>>> from ftplib import FTP >>> ftp = FTP('ftp.us.debian.org') # connect to host, default port >>> ftp.login() # user anonymous, passwd anonymous@ '230 Login successful.' >>> ftp.cwd('debian') # change into "debian" directory '250 Directory successfully changed.' >>> ftp.retrlines('LIST') # list directory contents -rw-rw-r-- 1 1176 1176 1063 Jun 15 10:18 README ... drwxr-sr-x 5 1176 1176 4096 Dec 19 2000 pool drwxr-sr-x 4 1176 1176 4096 Nov 17 2008 project drwxr-xr-x 3 1176 1176 4096 Oct 10 2012 tools '226 Directory send OK.' >>> with open('README', 'wb') as fp: >>> ftp.retrbinary('RETR README', fp.write) '226 Transfer complete.' >>> ftp.quit() '221 Goodbye.'