1, HTTP is mainly used for Web-based file download and access to Web services, the general client can access files and services on the server without having to log on. Most HTTP file transfer requests are used to obtain a Web page (the page file is downloaded locally).
2, FTP is mainly used to download public files anonymously, can also be used to transfer files between two computers. FTP requires a user name and password to access the FTP server, but it also allows users without an account to log on anonymously. However, the administrator must first set up an FTP server to allow anonymous users to log on. At this point, the user name of the anonymous user is "anonymous", the password is generally the user's e-mail address.
Work Flow:
The ① client connects to the FTP server on the remote host.
The ② client enters the user name and password (or "anonymous" and e-mail address).
③ Client for various file transfer and information query operations.
The ④ client exits from the remote FTP server and ends the transfer.
If the client is not responding for more than 15 minutes (900 seconds), the FTP connection times out and interrupts. At the bottom, FTP uses only TCP, not UDP. There are two modes of ftp: active and passive.
3. Python and FTP
From ftplib Import FTPF = FTP (' some.ftp.server ') f.login (' Anonymous ', ' [email protected] ') : F.quit ()
Methods for FTP objects
| Method |
Describe |
| Login (user= ", passwd=") |
Log in to the FTP server, all parameters are optional |
| CWD (PATH) |
Set current working directory to path as shown |
| Dir ([path[,... [, CB]]) |
Displays the contents of the path directory, the optional parameter CB is a callback function that is passed to the Retrlines () method |
| PWD () |
Get Current working directory |
| Storlines (CMD,F) |
Given the FTP command, it is used to upload text. To be given a file object F |
| Storbinary () |
Similar to the above, used to process binary files |
| Retrlines (CMD[,CB]) |
A given FTP command to download a text file. The optional callback function CB is used to process each row in the file. |
| Retrbinary |
Working with binary files |
| Quit () |
Close the connection and exit |
Python and FTP