Python and FTP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.