Implementing the FTP upload function

Now that the test server is up and running, let's build our FTP upload function and the logic for the GUI. While the standard library doesn't contain an FTP server library, it does contain an FTP client library in the form of the ftplib module.

Begin by importing ftplib into our network.py file:

import ftplib as ftp

An FTP session can be created using the ftplib.FTP class. Because this is a stateful session, it needs to be closed after we're done; to make sure we do this, FTP can be used as a context manager.

Let's start our function by connecting to the FTP server:

def upload_to_corporate_ftp( filepath, ftp_host, ftp_port, ftp_user, ftp_pass): with ftp.FTP() as ftp_cx: ftp_cx.connect(ftp_host, ftp_port) ...

Get Python GUI Programming with Tkinter 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.