Simple FTP File Download/Upload (C#)

Printer-friendly version

Recently, I was working on a solution which required a scheduled download of a hosted file. There are a few samples floating around online of how to do an FTP download/upload, but I figured I would share what I've been using as it is incredibly simple and does the job perfectly.

We utilize WebClient and NetworkCredential, so the System.Net namespace is required. Then, we just supply credentials and call either the DownloadFile() or UploadFile() method which require the source and destination folders - that's it! Below are examples of each.

 

//Download

using (WebClient ftpClient = new WebClient())

{

ftpClient.Credentials = new NetworkCredential("username", "password");

ftpClient.DownloadFile("ftp://www.mywebsite.com/test.html", @"C:\Temp\test.html");

}

 

//Upload

using (WebClient ftpClient = new WebClient())

{

ftpClient.Credentials = new NetworkCredential("username", "password");

ftpClient.UploadFile("ftp://www.mywebsite.com/test.html", @"C:\Temp\test.html");

}

About the Author:

TopLine Strategies delivers the complete integration and development of sales, marketing and customer service technologies that enable corporate clientele to improve revenue streams and strengthen customer interactions. Our project management and consulting is designed to achieve timely delivery, 100 percent user adoption of the technologies we implement and deliver measurable returns on investments for our clients.

Comments (0)

Related Blogs

TheReact Native Open Source roadmap was announced in Q4 2018 after they decided to invest more in the React Native open source community.

October is not just about pumpkins, fall foliage, and cooler temps anymore. October 2018 also means the exciting introduction of Microsoft Dynamics 365 for Customer Engagement.

Back in 2016, Microsoft introduced its intentions to refresh its CRM and ERP strategy with Dynamics 365. At the heart of its services was the Common Data Model (CDM).