Click here to Skip to main content
14,826,451 members
Articles / Programming Languages / C#
Posted 27 Mar 2003


216 bookmarked

FTP client library for C#

Rate me:
Please Sign up or sign in to vote.
4.77/5 (88 votes)
27 Mar 20031 min read
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

Comments and Discussions

QuestionBug in readLine() (and fix) Pin
MathiasNyman22-Mar-18 2:44
MemberMathiasNyman22-Mar-18 2:44 
QuestionMany functions don't work Pin
Member 1321498922-May-17 0:17
MemberMember 1321498922-May-17 0:17 
Questionplease provide the license Pin
user.7053-May-17 21:38
Memberuser.7053-May-17 21:38 
QuestionRipoff Pin
Member 1090501527-Jan-15 22:48
MemberMember 1090501527-Jan-15 22:48 
QuestionLicense for usage Pin
rahulsia817-Aug-14 18:11
Memberrahulsia817-Aug-14 18:11 
QuestionCan FTPClient library works with proxy server Pin
hkshahasane14-May-14 0:21
Memberhkshahasane14-May-14 0:21 
SuggestionProblem of performance Pin
Member 857641628-Jan-13 0:08
MemberMember 857641628-Jan-13 0:08 
GeneralMy vote of 5 Pin
Dametry18-Dec-12 16:55
MemberDametry18-Dec-12 16:55 
QuestionWhere can I download the library? Pin
cathy liang18-Aug-12 19:04
Membercathy liang18-Aug-12 19:04 
QuestionError Async Download!!! Pin
Edward Vargas28-Mar-12 9:53
MemberEdward Vargas28-Mar-12 9:53 
QuestionProblem using FTP Client on machines with Norton 360 Antivirus software Pin
andreyakub24-Oct-11 21:48
Memberandreyakub24-Oct-11 21:48 
GeneralFix error "Object reference not set to an instance of an object" when using class FtpWebRequest on Net 4.0 Pin
qdhoang8-Mar-11 21:31
Memberqdhoang8-Mar-11 21:31 
GeneralGood work Pin
lapeau21-Sep-10 3:08
Memberlapeau21-Sep-10 3:08 
GeneralProblem With IPv6 and Possible Solution Pin
GaroRobe15-Sep-10 14:34
MemberGaroRobe15-Sep-10 14:34 
GeneralError while uploading large files. Pin
faisaliqbalch14-Apr-10 6:37
Memberfaisaliqbalch14-Apr-10 6:37 
GeneralQuick Question Pin
vijayr8-Apr-10 3:04
Membervijayr8-Apr-10 3:04 
GeneralRe: Quick Question Pin
DaveAuld9-Apr-10 2:03
professionalDaveAuld9-Apr-10 2:03 
QuestionError When Trying Login Pin
SibiSurya13-Jan-10 21:36
MemberSibiSurya13-Jan-10 21:36 
Questiondownload problem Pin
new start6-Nov-09 0:19
Membernew start6-Nov-09 0:19 
AnswerRe: download problem Pin
new start6-Nov-09 0:40
Membernew start6-Nov-09 0:40 
GeneralThanks dude Pin
feisal30-Sep-09 5:17
Memberfeisal30-Sep-09 5:17 
QuestionThe Max number of Uploaded files Pin
fhy1977022729-Jul-09 20:46
Memberfhy1977022729-Jul-09 20:46 
Rantdownload doesnt work Pin
Habufe8-Jan-09 5:03
MemberHabufe8-Jan-09 5:03 
GeneralRe: download doesnt work Pin
Edward Vargas28-Mar-12 9:57
MemberEdward Vargas28-Mar-12 9:57 
Generalthis ftpserver is good! Pin
houzhifa9-Oct-08 1:02
Memberhouzhifa9-Oct-08 1:02 

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.