Transferring a file

So, now that we understand how the command connection to an FTP server is initiated under the hood, and how that allows us to open a data connection, let's use that to actually request a file. We'll use the same request processing structure we saw for building a request and then fetching the response back in Chapter 5, Generating Network Requests in C#. This should all feel pretty familiar at this point, but I will take advantage of a few of the FtpWebRequest class's specific properties to highlight some of the options at your disposal. So, let's write the method to download a file.

The first thing we'll do differently will be specifying the sub-directory path for the file we want to look up. We'll just use the Startup.cs ...

Get Hands-On Network Programming with C# and .NET Core 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.