SingingEels : Development Community & Resource

Login

Articles

  • ADO.NET (2)
  • ASP.NET (36)
  • LINQ (4)
  • Security (2)
  • Silverlight (3)
  • SQL (7)
  • Standards (5)
  • WCF (2)

Syndication

  • Articles RSS
  • Blogs RSS

Contribute

  • Our Authors List
  • Member Sign-Up
  • Suggestions Box
ASP.NET Hosting with MS SQL 2008 – Click Here!

Downloading and uploading to an FTP the easy way!

(Sep 08 2007 - 08:25:40 PM by Timothy Khouri) - [print blog post]

One of my biggest passions when it comes to programming has always been communication between computers (and networks), whether it be with raw communication with Sockets, Web Services, remoting or whatever. Just the thought of all that's going on behind the scenes to "connect" everyone together really blows my mind.

Along that line of thought is one of my favorite classes in the .NET framework, the WebClient class (in the System.Net namespace). I've always known of this class to upload and download files from a web server, but you can also use it for FTP servers too.

So without boring with too much talking, I'll show you how easy it is with some code:

// Make an instance of the WebClient class.
WebClient myLilWebClient = new WebClient();

// Since my FTP requires authentication, I'll have to supply my

// UserName and Password.

myLilWebClient.Credentials = new NetworkCredential("userName", "p@ssw0rd");

// Now I'll download a file from my FTP right to my desktop.

myLilWebClient.DownloadFile("ftp://myFtpAddress.com/somefile.txt", @"c:\documents and settings\tkhouri\desktop\somefile.txt");

I don't think it could get any easier than that! Oh, and if you wanted to Upload a file to an FTP... you'd simply call mYLilWebClient.UploadFile.

Gotta love .NET!

You must be logged in to add comments. If you have not already done so, you can create an account here. If you already are a member, you first need to login before you can comment.

Developer / Architect / Author

Blog Archives

  • November 2008 - (1)
  • October 2008 - (2)
  • September 2008 - (2)
  • August 2008 - (3)
  • July 2008 - (1)
  • June 2008 - (3)
  • May 2008 - (2)
  • April 2008 - (2)
  • March 2008 - (4)
  • February 2008 - (2)
  • December 2007 - (2)
  • November 2007 - (1)
  • October 2007 - (4)
  • September 2007 - (9)
  • August 2007 - (7)

Related Ads

SingingEels.com as of Jan 05 2009 - 05:42:11 PM - (0.078123)