How to use FTP in Python

ftp in python Sending a small file in an email as an attachment can work in many situations, but for large files this can be a painful process. FTP has made it easier for individuals and businesses to transfer files between different locations. File Transport Protocol , or FTP, is an open protocol standard that is widely used to transport and receive large files. FTP uses Transmission Control Protocol (TCP) to transfer files from one location to another. Python ftplib module defines the class FTP and a few related items. The FTP class implements the client side of the FTP protocol . You can use this to write Python programs that perform a variety of automated FTP jobs, such as downloading files from Server. The following Python program create an FTP client and downloading a file from Server.
import os import ftplib ftpServer = ftplib.FTP('', 'anonymous','you email address') ftpServer.retrlines("LIST") dirList = [] ftpServer.retrlines("LIST", dirList.append) str = dirList[0].split(None, 8) filename = str[-1].lstrip() print("Dowloading File :: ",filename) localPath = os.path.join(r"D:\ftp\dowloads", filename) file = open(localPath, "wb") ftpServer.retrbinary("RETR " + filename, file.write, 8*1024) file.close() print("Done !!") print("Please check your downloded file : D:\ftp\dowloads")