Click here to Skip to main content
13,350,861 members (66,479 online)
Click here to Skip to main content
Add your own
alternative version


43 bookmarked
Posted 16 Sep 2003

C# FTP client, based on the WinInet.dll API

, 16 Sep 2003
Rate this:
Please Sign up or sign in to vote.
The WinInet.dll API is able to tunnel through firewalls - this simple FTP client will support file transfer even when your firewall has only port 21open!


When I needed to add automated file transfer to and from a remote FTP server, I found any number of excellent, clear, well structured and beautifully documented examples; both commercial and private - and all useless to me! Our Internet access is over a rather 'well throttled' firewall that seems to only have port 21 left open. The classic sockets approach to implementing an FTP client will open a 'command channel' over port 21 (default FTP port), allowing the client to sign-on etc., but as soon as any data is required to flow a second, 'data channel' must be opened (default port 20). Active or passive, I could not establish a second channel through our firewall.

I would have given up at this stage and started to look for a new employer, when it occurred to me that the Windows Explorer was perfectly able to exchange data with all and any FTP server I pointed it at... this runs over exactly the same firewall, so something strange and not just a bit magical is happening here. It turns out this bit of magic is to be found in the WinInet.dll. I am still not quite sure how the WinInet.dll works, it seems to sweet talk the firewall into opening just a small chink in its armor - but the important thing is that it works!

In order to use the FTP features of WinInet.dll, I needed to encapsulate the API in C#. This was mostly pain free, except for the marshaling of string parameters - it is documented, but you have to know what to look for. Having finished this, I figured I could offer it to the C# community; maybe I will save somebody many frustrating hours trying to bore through his corporate firewall, but also because I am quite sure I am going to get a bunch of really helpful feedback... for example, why does a successful file deletion return error code 2 = file not found? Ah, the mysteries of API programming.

I have included a very minimal console application to test the basic functionality - the default URL is, users are invited to replace this with their own target.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Peter Beedell
Web Developer
Germany Germany
As a Brit who sacrificed warm beer baked beans for Bayerisch lager and Bratwurst about 12 years ago, I feel European and proud of it!

You may also be interested in...

Comments and Discussions

GeneralRe: NLST using FtpCommand Pin
Jaze28-Sep-05 5:12
memberJaze28-Sep-05 5:12 
GeneralAn Asembly Code for sending Data to server Pin
Zeeshan_lqp10-Sep-04 11:46
memberZeeshan_lqp10-Sep-04 11:46 
Questionwin 98 / 2000 supported? Pin
Tim_Mackey17-Aug-04 3:56
memberTim_Mackey17-Aug-04 3:56 
AnswerRe: win 98 / 2000 supported? Pin
Tim_Mackey19-Aug-04 5:12
memberTim_Mackey19-Aug-04 5:12 
GeneralFtpCommand Pin
gnanib15-Jun-04 10:30
membergnanib15-Jun-04 10:30 
GeneralRe: FtpCommand Pin
marcinsulima7-May-05 13:55
membermarcinsulima7-May-05 13:55 
GeneralIncorrect password Pin
Udaan200313-Feb-04 13:46
memberUdaan200313-Feb-04 13:46 
GeneralProgress Bar Pin
Jeffrey Scott Flesher15-Dec-03 13:25
memberJeffrey Scott Flesher15-Dec-03 13:25 
How do you add a progress bar.

Lessons learned from 911:

1. United We Stand.

2. United’s We Fall.

Gulf War Syndrome survivors never have a good day.
QuestionAny other alternatives? Pin
sxlu18-Nov-03 11:41
membersxlu18-Nov-03 11:41 
AnswerRe: Any other alternatives? Pin
Anonymous29-Dec-03 7:07
sussAnonymous29-Dec-03 7:07 
AnswerRe: Any other alternatives? Pin
krprasad19-Jan-04 11:41
memberkrprasad19-Jan-04 11:41 
GeneralFTP Connection not working Pin
girishnadig18-Sep-03 7:38
membergirishnadig18-Sep-03 7:38 
GeneralDefault data port is 20 Pin
cwkingjr17-Sep-03 20:05
membercwkingjr17-Sep-03 20:05 
GeneralRe: Default data port is 20 Pin
Peter Beedell17-Sep-03 21:33
memberPeter Beedell17-Sep-03 21:33 
GeneralSource Files Download Link Broken Pin
fbougadou17-Sep-03 6:12
memberfbougadou17-Sep-03 6:12 
GeneralRe: Source Files Download Link Broken Pin
Peter Beedell17-Sep-03 21:34
memberPeter Beedell17-Sep-03 21:34 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 17 Sep 2003
Article Copyright 2003 by Peter Beedell
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid