Click here to Skip to main content
15,867,986 members
Articles / Programming Languages / C#
Article

An "easy to use" FTP client library

Rate me:
Please Sign up or sign in to vote.
2.61/5 (18 votes)
9 May 2006 62.4K   1.6K   32   14
Get connected to your FTP server

Introduction

The .Net Framework 2.0 has built-in support for accessing FTP server through the FtpWebRequest and FtpWebResponse classes.

This library provides easy access to the most common operations against FTP servers by providing an easy interface against this new features in the .Net 2.0 Framework.

I am sure there is a lot more to FTP than what is covered here, but if your needs are simple, this may be a starting point.

Using the library

Say that you want to upload a file to a remote FTP server.

The following example shows how to use FtpDotNet to accomplish this task.

C#
try
 {
     FtpConnection connection = new FtpConnection();
     connection.MessageReceived += new FtpConnectionEventHandler(connection_MessageReceived);
     connection.Host = "ftp://ftp.myserver.com";
     connection.UserName = "username";
     connection.Password = "password";
     connection.RemoteDirectory = "/MyDirectory";
     connection.Upload(@"C:\Temp\House.jpg", "House.jpg");
 }
 catch (WebException ex)
 {
     Console.WriteLine(ex.ToString());
 }
 catch (Exception ex)
 {
     Console.WriteLine(ex.ToString());
 }

 

The connection object has an event called Messagereceived where you can retrieve response messages sent from the  FTP server during operations.

<PRE class=code>void connection_MessageReceived(object sender, FtpConnectionEventArgs e)
{
    Console.WriteLine(e.Message);
}

 

 


 

License

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


Written By
Software Developer
Norway Norway
I'm a 39 year old software developer living in Norway.
I'm currently working for a software company making software for the retail industry.

Comments and Discussions

 
QuestionHow to Add % complete or Bytes send during the upload? Pin
wozzarvl17-Apr-15 6:40
wozzarvl17-Apr-15 6:40 
Question<DIR> is not handled by regular expression Pin
pvolchek20-Jul-11 9:13
pvolchek20-Jul-11 9:13 
Generalgood! Pin
yuyejian3-Jun-10 23:00
yuyejian3-Jun-10 23:00 
GeneralA comfortable FTP class in .NET Pin
Elmue27-Aug-08 12:40
Elmue27-Aug-08 12:40 
QuestionLicense Pin
KITTA196424-Mar-08 0:53
KITTA196424-Mar-08 0:53 
GeneralRe: License Pin
seesharper1-Apr-08 8:04
seesharper1-Apr-08 8:04 
QuestionProxy Pin
tarantula325-Jan-08 12:36
tarantula325-Jan-08 12:36 
GeneralCreateWebRequest fails Pin
ccengine8-Oct-07 1:23
ccengine8-Oct-07 1:23 
GeneralThe remote server returned an error: (530) Not logged in Pin
Charles Meyer17-Feb-07 10:00
Charles Meyer17-Feb-07 10:00 
GeneralRe: The remote server returned an error: (530) Not logged in Pin
MH253817-Mar-07 0:47
MH253817-Mar-07 0:47 
GeneralThank You! Pin
DORMark10-Jan-07 6:45
DORMark10-Jan-07 6:45 
QuestionQuestions... [modified] Pin
Christopher Stratmann10-Nov-06 5:28
Christopher Stratmann10-Nov-06 5:28 
Generalabout DirectoryList [modified] Pin
Alper Hankendi11-Oct-06 22:44
Alper Hankendi11-Oct-06 22:44 
QuestionNice FTP code but need some help. Pin
Adnan Jamil15-Jun-06 8:19
Adnan Jamil15-Jun-06 8:19 

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.