FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://example.com/file.txt"); request.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); // Download file code here response.Close();
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) { // Download file code here }This example also downloads a file from an FTP server, but the response is enclosed in a using statement. This ensures that the response is automatically closed and disposed of when the code in the using block is complete. Package Library: System.Net.