Click here to Skip to main content
11,643,493 members (74,252 online)
Click here to Skip to main content

FTP client library for C#

, 27 Mar 2003 378.9K 9.3K 208
Rate this:
Please Sign up or sign in to vote.
FTP client library for C#, including asynchronous operations.


Finding a fully working, lightweight FTP client, that had no GUI, was free, and came with source code, was difficult. This API is based on a work, Jaimon Mathew had done, and I have added some methods, cleaned up the code, debugged it and added some error handling, logging, debugging etc.

It is easy to use. Here is a code example:

FtpClient ftp = new FtpClient(FtpServer,FtpUserName,FtpPassword);

Not so difficult now, is it? I am using it in my WebCamService list on this site, so if you want to see it in action, go here.

I started out wrapping fully the WinInet API, but it was such a labourous task that it made sense just to do the FTP. Since Microsoft has great support for HTTP, I could skip that, and later work on SMTP.


  • Upload
  • Recursive upload
  • Download
  • Resume
  • Delete
  • Rename
  • Create directory
  • Asynchronous operation


  • Not fully tested
  • No real error handling
  • No download recourse yet
  • Rename will overwrite, if the target already exists

Asynchronous operation

A little more advanced, the asynchronous operation is used when you need the job, to fork while your code continues over the method. All asynchronous methods start with Begin.

Using it is simple. You need a couple of things, an AsyncCallback object and a method which it handles.

private FtpClient ftp = null;

private void UploadPicture(string imagePath)
    string FtpServer = ConfigurationSettings.AppSettings["FtpServer"];
    string FtpUserName = ConfigurationSettings.AppSettings["FtpUserName"];
    string FtpPassword = ConfigurationSettings.AppSettings["FtpPassword"];

    AsyncCallback callback = new AsyncCallback(CloseConnection);

    ftp = new FtpClient(FtpServer,FtpUserName,FtpPassword);
    ftp.BeginUpload(imagePath, callback);

private void CloseConnection(IAsyncResult result)

    if ( ftp != null ) ftp.Close();
        ftp = null;

When the upload finishes or throws an exception, the CloseConnection method will be called.


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

Dan Glass
Australia Australia

You may also be interested in...

Comments and Discussions

GeneralProxy Support for FTP client Pin
drkalucard3-May-05 23:40
memberdrkalucard3-May-05 23:40 
GeneralAnother free, open-source .NET FTP component Pin
Hans Andersen11-Nov-04 11:45
sussHans Andersen11-Nov-04 11:45 
QuestionHave any body here actualy looked at the code? Pin
Arnt1-Nov-04 12:31
memberArnt1-Nov-04 12:31 
GeneralNot working Pin
agolovan29-Sep-04 14:50
memberagolovan29-Sep-04 14:50 
GeneralRe: Not working Pin
mohit bhat18-Nov-04 3:22
membermohit bhat18-Nov-04 3:22 
GeneralRe: Not working Pin
Anonymous24-Jan-05 19:06
sussAnonymous24-Jan-05 19:06 
GeneralIt doesn't work with the IIS FTP server if a welcome message is set Pin
JustinCouto9-Jun-04 6:15
memberJustinCouto9-Jun-04 6:15 
GeneralRe: It doesn't work with the IIS FTP server if a welcome message is set Pin
Jose Lopes da Cruz25-Aug-04 5:34
memberJose Lopes da Cruz25-Aug-04 5:34 
GeneralRe: It doesn't work with the IIS FTP server if a welcome message is set Pin
GoToSleep22-Sep-05 5:41
memberGoToSleep22-Sep-05 5:41 
QuestionNo File Uploading??? Pin
_stormbringer_20-May-04 10:15
suss_stormbringer_20-May-04 10:15 
Generalasync Pin
toni113-May-04 4:13
membertoni113-May-04 4:13 
GeneralBetter version. Pin
Dan Glass10-May-04 11:55
memberDan Glass10-May-04 11:55 
GeneralRe: Better version. Pin
Anonymous11-May-04 5:32
sussAnonymous11-May-04 5:32 
GeneralRe: Better version. Pin
Anonymous11-May-04 6:14
sussAnonymous11-May-04 6:14 
GeneralRe: Better version. Pin
Anonymous11-Oct-04 22:11
sussAnonymous11-Oct-04 22:11 
GeneralI keep getting 530 Login or Password incorrect Pin
Anonymous10-May-04 11:46
sussAnonymous10-May-04 11:46 
GeneralThanks a ton. Pin
supertedusa21-Apr-04 8:59
membersupertedusa21-Apr-04 8:59 
GeneralTwo Thumbs Up Pin
Gitaraman21-Mar-04 19:15
memberGitaraman21-Mar-04 19:15 
GeneralAsync feature is smoke and mirrors Pin
Ed Brey6-Mar-04 11:18
memberEd Brey6-Mar-04 11:18 
GeneralChange file permissions Pin
hemko124-Feb-04 4:14
memberhemko124-Feb-04 4:14 
GeneralRe: Change file permissions Pin
Andrlage3-May-07 12:57
memberAndrlage3-May-07 12:57 
GeneralSwitch passive mode! Pin
Marc Schneider9-Feb-04 6:21
memberMarc Schneider9-Feb-04 6:21 
GeneralShould implement IDisposable Pin
Ed Brey3-Feb-04 0:08
memberEd Brey3-Feb-04 0:08 
GeneralGr8 one.... but two big bugs Pin
Anonymous11-Jan-04 16:34
sussAnonymous11-Jan-04 16:34 
GeneralRe: Gr8 one.... but two big bugs Pin
dtelford7-Apr-04 11:40
memberdtelford7-Apr-04 11:40 
GeneralWorks fine for me ! Pin
lurkbat9-Jan-04 2:10
memberlurkbat9-Jan-04 2:10 
GeneralBug in readLine() Pin
FifaRules30-Dec-03 7:21
memberFifaRules30-Dec-03 7:21 
General11226 Transfer Complete. throws FTPException Pin
Aleks111111117-Dec-03 17:42
memberAleks111111117-Dec-03 17:42 
Generalpassive mode Pin
ic3man17-Dec-03 7:21
memberic3man17-Dec-03 7:21 
Generalbug found in FTPFactory.cs Pin
ooooops16-Dec-03 3:51
memberooooops16-Dec-03 3:51 
QuestionAsync method tool? Pin
Nathan Davis21-Nov-03 7:39
memberNathan Davis21-Nov-03 7:39 
QuestionIs there a better workaround for timing problems? Pin
faylore27-Oct-03 19:02
memberfaylore27-Oct-03 19:02 
AnswerRe: Is there a better workaround for timing problems? Pin
mcbevin11-Nov-03 11:24
membermcbevin11-Nov-03 11:24 
GeneralRe: Is there a better workaround for timing problems? Pin
reubenf17-May-04 11:44
memberreubenf17-May-04 11:44 
GeneralExcellent job Pin
Riedwhan20-Oct-03 22:16
memberRiedwhan20-Oct-03 22:16 
GeneralSlow over internet Pin
Andrew Jones11-Oct-03 1:12
memberAndrew Jones11-Oct-03 1:12 
GeneralProblem downloading big files Pin
Anonymous9-Oct-03 18:54
sussAnonymous9-Oct-03 18:54 
GeneralProblem Downloading after ChangeDir Pin
John Gerding25-Sep-03 4:58
memberJohn Gerding25-Sep-03 4:58 
GeneralGoddamme it,it's pretty good =) Pin
SuMa_cn19-Sep-03 16:49
sussSuMa_cn19-Sep-03 16:49 
Generali like it Pin
winux7-Aug-03 7:40
memberwinux7-Aug-03 7:40 
Questionnice job, but where is the directory listing? Pin
raul_cel_mare12-Jul-03 22:50
memberraul_cel_mare12-Jul-03 22:50 
GeneralAwesome! Pin
Jamie Nordmeyer27-Jun-03 9:50
memberJamie Nordmeyer27-Jun-03 9:50 
GeneralNice Job, but a few comments... Pin
pbible16-Jun-03 12:24
memberpbible16-Jun-03 12:24 
GeneralRe: Nice Job, but a few comments... Pin
MrBumpy2-Feb-04 1:48
memberMrBumpy2-Feb-04 1:48 
GeneralRe: Nice Job, but a few comments... Pin
dtelford7-Apr-04 11:42
memberdtelford7-Apr-04 11:42 
GeneralLike the this statements. Where are directories? Pin
M K5-Jan-06 6:22
memberM K5-Jan-06 6:22 
GeneralReally Great Pin
chito16-Jun-03 1:46
memberchito16-Jun-03 1:46 
Generalsftp Pin
barnseyboy2-Apr-03 10:19
memberbarnseyboy2-Apr-03 10:19 
GeneralQuestion about the methods 'Upload' and 'createDataSocket' Pin
lesta2-Apr-03 10:04
memberlesta2-Apr-03 10:04 
GeneralRe: Question about the methods 'Upload' and 'createDataSocket' Pin
Jamie Nordmeyer3-Feb-04 8:39
memberJamie Nordmeyer3-Feb-04 8:39 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150731.1 | Last Updated 28 Mar 2003
Article Copyright 2003 by Dan Glass
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid