Transferring files with FTP

Unlike SFTP, FTP uses the plain-text file transfer method. This means any username or password transferred through the wire can be detected by an unrelated third-party. Even though FTP is a very popular file transfer protocol, people frequently use this for transferring a file from their PCs to the remote servers.

In Python, ftplib is a built-in module used for transferring the files to and from the remote machines. You can create an anonymous FTP client connection with the FTP() class.

ftp_client = ftplib.FTP(path, username, email)   

Then you can invoke the normal FTP commands, such as CWD. In order to download a binary file, you need to create a file-handler such as the following:

file_handler = open(DOWNLOAD_FILE_NAME, ...

Get Learning Python Network Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.