Python, FTP, and PythonFTP

Source: Internet
Author: User

Python, FTP, and PythonFTP

1. HTTP is mainly used to download Web-based files and access Web services. Generally, the client can access files and services on the server without logon. Most HTTP file transfer requests are used to obtain a webpage (that is, to download a webpage file to a local device ).

2. FTP is mainly used to download public files anonymously or transfer files between two computers. FTP requires that you enter the user name and password to access the FTP server, but users without accounts are allowed to log on anonymously. However, the Administrator must first set up an FTP server to allow anonymous users to log on. In this case, the anonymous user name is "anonymous" and the password is generally the user's email address.

Workflow:

① The client connects to the FTP server on the remote host.

② Enter the user name and password (or "anonymous" and email address) on the client ).

③ The client performs various file transmission and information query operations.

④ The client exits from the remote FTP server and ends the transmission.

If the client has not responded for more than 15 minutes (900 seconds), the FTP connection times out and is interrupted. At the underlying layer, FTP only uses TCP instead of UDP. FTP has two modes: active and passive.

 

3. Python and FTP

from ftplib import FTPf = FTP('some.ftp.server')f.login('anonymous','your@email.address')    :f.quit()

FTP object Method

Method Description
Login (user = '', passwd = '') Log on to the FTP server. All parameters are optional.
Cwd (path) Set the current working directory to the path shown in path
Dir ([path [,... [, cb]) Display the content in 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) Specifies an FTP command to upload text. To specify a file object f
Storbinary () Similar to the above, used to process binary files
Retrlines (cmd [, cb]) A given FTP command is used to download text files. The optional callback function cb is used to process each row in the file.
Retrbinary Processing binary files
Quit () Close the connection and exit

 

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.