>>> from ftplib import FTP_TLS
>>> ftps = FTP_TLS('ftp.python.org')
>>> ftps.login('usr', 'pwd') # login anonymously before securing control channel
>>> ftps.prot_p() # switch to secure data connection
>>> ftps.dir() # list directory content securely
total 9
drwxr-xr-x 8 root wheel 1024 Jan 3 1994 .
drwxr-xr-x 8 root wheel 1024 Jan 3 1994 ..
drwxr-xr-x 2 root wheel 1024 Jan 3 1994 bin
drwxr-xr-x 2 root wheel 1024 Jan 3 1994 etc
d-wxrwxr-x 2 ftp wheel 1024 Sep 5 13:43 incoming
drwxr-xr-x 2 root wheel 1024 Nov 17 1993 lib
drwxr-xr-x 6 1094 wheel 1024 Sep 13 19:07 pub
drwxr-xr-x 3 root wheel 1024 Jan 3 1994 usr
-rw-r--r-- 1 root root 312 Aug 1 1994 welcome.msg
>>> ftps.quit()
>>>
我这边试验,ftps = FTP_TLS('ftp.python.org')报错socket.error: [Errno 101] Network is unreachable。
exception ftplib.error_reply
Exception raised when an unexpected reply is received from the server. 从服务器接收到非预期的reply时产生。
exception ftplib.error_temp
Exception raised when an error code signifying a temporary error (response codes in the range 400–499) is received. 接收到临时错误(范围400-499响应代码)。
exception ftplib.error_perm
Exception raised when an error code signifying a permanent error (response codes in the range 500–599) is received. 接收到永久性的错误(范围500-599响应代码)。。
exception ftplib.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. 不符合FTP响应规格的响应,即1-5开头的数字。
ftplib.all_errors
The set of all exceptions (as a tuple) that methods of 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 socket.error and IOError.FTP示例的异常集合,为元组,包含以上4种异常和socket.error和IOError
模块netrc可以解析.netrc文件,FTP客户端通常使用.netrc文件加载用于验证信息。python源码中的Tools/scripts/ftpmirror.py可以镜像FTP站点,可以看做本模块的实例。
Return the welcome message sent by the server in reply to the initial connection. (This message sometimes contains disclaimers or help information that may be relevant to the user.)