Click here to Skip to main content
Click here to Skip to main content

FTP Client and HttpFileDownloader Components (Controls)

By , 25 Jun 2008
 

Introduction

Once I needed a simple, open source, and robust FTP client to include in my project. To my surprise, I was not able to find one in spite of many FTP clients that were published on various websites including CodeProject. The problem was the quality: the published projects were just demos. There were no quality FTP clients.

According to ratings, the most popular CodeProject FTP client is available here: An FTP client library for .NET 2.0. In spite of numerous fixes, the component did not work as I anticipated. And the major problem is not in the fixes (some of them were quite reasonable) - the problem is in the underlying FtpWebRequest component itself.

The component is designed to operate in stateless mode. One can only guess what the reasons were behind such a “wise” decision. FTP is a connection based protocol, and any attempt to fit a connection based protocol into a connectionless component apparently can not work well, by definition. First, what can we possibly benefit out of relinquishing the control over the connection status? The connection will not go away even if you hide it somewhere - it is the protocol's property, not the component’s. I can only think that the designers of this component intended to keep the component in line with HttpWebRequest. But, the difference is that the HTTP protocol is stateless by nature and FTP is not.

FtpWebRequest problems

So, what is wrong with FtpWebRequest? The main problem is the response time. The connection to the server of any FTP client took about 2.5 seconds. FtpWebRequest consistently showed 13.5 seconds (when connected to the same site). No customer would tolerate an extra 11 seconds delay without reason (440% increase). Apart from that, if you do not explicitly set KeepConnectionAlive to false, the system would not work properly. (It is supposed to be false, by default.)

The solution

Luckily, I found a good solution in the aforementioned article's comments. The solution is edtFTPnet. It is an open source library of the highest quality (believe it or not). The library is designed by Enterprise Distributed Technologies. They also have advanced versions of FTP components (with SSL and other features), but they are not free. The only problem with the open source one is that it lacks multithreading support. But that is not a real problem – a multithreading wrapper can be created for almost anything if you have experience. This component is a multithreading wrapper for edtFTPnet designed as a Windows Forms control, with some minor additions like status bar support and threads handling.

Core features

  • Runs in a separate thread.
  • Ability to cancel the transfer at any time.
  • Progress bar support.
  • Displays estimated time left.
  • Displays transfer speed.

How to use the controls

Copy the root directory (and subdirectories) to any location. Create a new tab in the Visual Studio Toolbox. Register the library with the Visual Studio Toolbox by browsing for FTPLib. You will be able to see the controls on the tab.

Drag the control to your form. Place the progress bar on the form. Select your FtpControl and select your status bar in the ProgrBar control’s properties.

Create a status event by selecting and double clicking StatusUpdateEvent.

The rest is quite clear from the samples.

HttpFileDownloader

The second component is a HttpFileDownloader component (control). Both components inherit from the BaseDownloader component.

New version

If a newer version is released, it will be available here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Alex_1
Web Developer
Australia Australia
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralTHREAD PROBLEMmembermnek8421 Apr '09 - 1:55 
The issues comes when you want to download more than one file, the state get's busy after the first one and there is no possible to download other file
GeneralSetLocalFolder not working...memberabakshi18 Dec '08 - 3:03 
For the HttpFileDownloader, the SetLocalFolder routine doesn't seem to be working. Even in the demo program provided, it always downloads the file to the application startup folder...
Questionencoding?memberParkInSung1 Dec '08 - 18:15 
Hi~ Good prgogram!!
But, How do I take care of the following encoding?
 
--> Encoding.GetEncoding("ks_c_5601-1987") or Encoding.GetEncoding("euc-kr") ?
 
pisjjang

GeneralProblem with edtFTPnetmemberinfoss21 Aug '08 - 21:49 
Hi ! - I have tried the edtFTPnet-component - it has a major bug as far as i can see... - Try doin this : " TheClient.Get("*.txt", "*.txt") " - after this "error" you can't disconnect from the server before you exit your application... - Some strange reference will hold some part of your object - also if you make a "TheClient = nothing" (VB) ! Cry | :((
GeneralGreat projectmemberhardsoft26 Jun '08 - 12:34 
I not looked at this yet but does it account for proxy servers so you can supply a username, password and proxy server etc?
GeneralRe: Great projectmemberAlex_126 Jun '08 - 16:39 
No proxies at a moment
GeneralGood jobmemberbilo8125 Jun '08 - 22:18 
Good article!
Only a suggestion, maybe I have not seen it while I went through your code, could be good to support the use of a proxy also for the FTP Client...
Thanks for sharing and keep up the good work
GeneralRe: Good jobmemberAlex_126 Jun '08 - 16:52 
No plans to support proxies at a moment. If somebody does this job,
I can certainly include it in the code.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 25 Jun 2008
Article Copyright 2008 by Alex_1
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid