Click here to Skip to main content
Click here to Skip to main content

An "easy to use" FTP client library

By , 9 May 2006
 

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.

<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

About the Author

seesharper
Software Developer
Norway Norway
Member
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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: The remote server returned an error: (530) Not logged inmemberMH253817 Mar '07 - 0:47 
Do you set username and password.
I use this dll in my project and work properly.
GeneralThank You!memberDORMark10 Jan '07 - 6:45 
I was looking for a project that implemeted the 2.0 framework. I needed to use SSL. All I had to do was implement the boolean for the enable SSL and it worked. I did have to override the delegate for the certificate, but that was a few lines and it is done. I too, had to change the code for the list directory.
 
I really like the documentation. How did you get the information into the ftpdotnet.chm?
QuestionQuestions... [modified]memberchris17510 Nov '06 - 5:28 
I really like the way everything is setup. I noticed a few things that may make this a better class...
 
1. Why don't you use the "using" statement inplace of the try and finally statements? I think this could make your code more simple.
 
2. I really like the DownloadFiles function. Why isn't there an UploadFiles function?
 
3. What about coping directories? Is there a way to download and upload directories and or their subdirectories?
 
4. Noticed you are using Path.GetTempFileName() and then moving the file. You could use a MemoryStream and then use BinaryWriter to write the file.
 
Thanks
 
Chris
 

 
-- modified at 14:49 Friday 10th November, 2006
Generalabout DirectoryList [modified]memberAlper Hankendi11 Oct '06 - 22:44 
thanks for code.but have a little problem.
 
FTPConnection.cs
 
Line 591 :
FtpWebRequest ftpWebRequest = CreateWebRequest(WebRequestMethods.Ftp.UploadFileWithUniqueName, remotePath);
 
Replace
 
FtpWebRequest ftpWebRequest = CreateWebRequest(WebRequestMethods.Ftp.ListDirectory, remotePath);
 

thanks again..
QuestionNice FTP code but need some help.memberAdnan Jamil15 Jun '06 - 8:19 
Hi,
 
Thanks for this code. This was easy to implement. I am using your code in my applicaiton but getting below error message. I haven't figure out how to fix it. Could you please let me guid.
 
Error
The remote server return an error: (407) Proxy Authentication Required.
 
My network guys told me they are not using any Proxy Server.
 
Thanks for all your help.
 
Adnan Jamil

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 10 May 2006
Article Copyright 2006 by seesharper
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid