65.9K
CodeProject is changing. Read more.
Home

An "easy to use" FTP client library

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.61/5 (18 votes)

May 10, 2006

viewsIcon

64140

downloadIcon

1574

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.

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.

void connection_MessageReceived(object sender, FtpConnectionEventArgs e)
{
    Console.WriteLine(e.Message);
}

 

 


 

An "easy to use" FTP client library - CodeProject