python ftp
Today we will learn about python ftp operations. FTP is an acronym for File Transfer Protocol. Just like what it sounds, this protocol is used to transfer files across a network from source to destination machine.
今天,我们将学习python ftp操作。 FTP是文件传输协议的缩写。 就像听起来一样,此协议用于在网络上从源计算机到目标计算机传输文件。
In this post on python ftp module, we will see how to connect to a FTP server, upload & download files and much more. Let’s get started.
在python ftp模块的这篇文章中,我们将看到如何连接到FTP服务器,上传和下载文件等等。 让我们开始吧。
Python的FTP (Python ftp)
With Python, ftplib
module provides all the functions which we might need to perform actions across the FTP protocol. Let’s start exploring this lesson with simple connection attempt.
使用Python, ftplib
模块提供了我们可能需要跨FTP协议执行操作的所有功能。 让我们通过简单的连接尝试开始本课。
使用login()函数连接到FTP服务器 (Connecting to an FTP server with login() function)
We will start by making a connection to an FTP server. We will use a server publicly available for usage, ftp.cse.buffalo.edu
. Feel free to choose any server, just make sure you select the right server otherwise you will face connection errors.
我们将从建立与FTP服务器的连接开始。 我们将使用可供使用的ftp.cse.buffalo.edu
服务器ftp.cse.buffalo.edu
。 随意选择任何服务器,只需确保选择正确的服务器,否则将面临连接错误。
We will write a simple script to connect to the said server:
我们将编写一个简单的脚本来连接到所述服务器:
from ftplib import FTP
# Host to connect to
host = 'ftp.cse.buffalo.edu'
# Make an Python FTP object and anonymously login
ftp = FTP(host)
print(ftp.login())
See how we can login without a username and a password? That is supported by few servers only. Let us see the output: