Click here to Skip to main content
16,018,092 members
Articles / Programming Languages / C#

C# FTP Client Library

Rate me:
Please Sign up or sign in to vote.
4.65/5 (24 votes)
23 May 2007CPOL1 min read 272.6K   4.3K   124   83
Easy to use FTP client library with features in mind.

Introduction

This code is an FTP class library for adding FTP access to your projects. It is heavily based on a project (see background for original code), and is now contained in the source files. I was not sure how to update the original article or add to it so I am publishing this as a new article since there was an extensive re-work of the original code in an attempt to make it more developer-friendly.

Background

This article, and code, are based upon the ftplib posted by J.P. Trosclair. A link to the article is here. I have left original copyright and credit notices in with the updated version of the code.

Using the code

I used nDoc to create a CHM file (in the doc directory of the code) to help with implementation. Its fairly simple, and you will mainly need basic FTP connection information (IP, username, etc.) to use the library.

An example is included in the documentation, and appears as so (to upload a file):

C#
OpenFTP.FTP f = new OpenFTP.FTP();
f.Connect("127.0.0.1", "username_here", "password_here");
f.ChangeDirectory("somedirectory");
f.Files.Upload(Path.GetFileName(sFileName), Path.GetFileName(sFileName));

while (!f.Files.UploadComplete)
{
    Console.WriteLine("Uploading: TotalBytes: " + 
        f.Files.TotalBytes.ToString() + ", : PercentComplete: " + 
        f.Files.PercentComplete.ToString());
}
Console.WriteLine("Upload Complete: TotalBytes: " + 
    f.Files.TotalBytes.ToString() + ", : PercentComplete: " + 
    f.Files.PercentComplete.ToString());

f.Disconnect();
f = null;

Points of Interest

I liked the original article but decided that even though I could read and implement the code I wanted its implementation to be more simplistic so months later I won't have to re-read any code to figure how to include the methods in a new project. I have tried to remove the rough edges.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Anonymous Proxy Anonymous Proxy
I am a Senior-level .NET developer using C# for about 5+ years now.

Codeproject has been a tremendous resource for me over the years.

Comments and Discussions

 
QuestionHow can I use download file ? Pin
Wat Thanaphong18-Jun-18 22:37
Wat Thanaphong18-Jun-18 22:37 
QuestionThank you Pin
Jason asdf29-Apr-14 11:52
Jason asdf29-Apr-14 11:52 
QuestionHow to check if the connection is established? Pin
AnLa06109527-Jun-11 4:08
AnLa06109527-Jun-11 4:08 
GeneralAlex FTPS Client Pin
B.Ritter5-Mar-11 0:09
B.Ritter5-Mar-11 0:09 
Generalexpect a demo Pin
pclion13-Feb-11 22:55
pclion13-Feb-11 22:55 
i don't know how the many methods and properties to be used.



            FTP ftp = new FTP();<br />
            if (textBox3.Text.Trim().Length == 0)<br />
                ftp.Connect(textBox1.Text, textBox2.Text, textBox4.Text);<br />
            else<br />
                ftp.Connect(textBox1.Text, int.Parse(textBox3.Text), textBox2.Text, textBox4.Text);<br />
<br />
            List<string> list = new List<string>();<br />
            foreach (FTP.Directory dir in ftp.Directories)<br />
            {<br />
                list.Add(dir.DirectoryName);<br />
            }<br />
            foreach (FTP.File f in ftp.Files)<br />
            {<br />
                list.Add(f.FileName);<br />
            }


but it retrieved nothing.
pclion

GeneralNot work in download .. Pin
AlexB4712-Feb-11 7:33
AlexB4712-Feb-11 7:33 
GeneralBug solutions Pin
robnet17-Aug-10 0:28
robnet17-Aug-10 0:28 
GeneralRe: Bug solutions Pin
B.Ritter1-Nov-10 6:37
B.Ritter1-Nov-10 6:37 
QuestionI cannot get the listing of the files plus other bugs Pin
Evandrojr2-Mar-10 10:22
Evandrojr2-Mar-10 10:22 
GeneralActive Mode Pin
liglio27-Jan-10 14:33
liglio27-Jan-10 14:33 
GeneralRe: Active Mode Pin
jmers27-Jan-10 17:13
jmers27-Jan-10 17:13 
GeneralRe: Active Mode Pin
liglio28-Jan-10 3:13
liglio28-Jan-10 3:13 
GeneralRe: Active Mode Pin
Daniel Castenholz29-Jan-10 8:22
Daniel Castenholz29-Jan-10 8:22 
QuestionSocketException Error Code 11004 Pin
Brisingr Aerowing10-Jan-10 10:54
professionalBrisingr Aerowing10-Jan-10 10:54 
AnswerRe: SocketException Error Code 11004 Pin
jmers10-Jan-10 15:18
jmers10-Jan-10 15:18 
Questionupload folder Pin
Direkt200718-Nov-09 4:07
Direkt200718-Nov-09 4:07 
GeneralCF 3.5 Pin
Gateone7512-Aug-09 2:32
Gateone7512-Aug-09 2:32 
RantLOL Pin
Seishin#8-Apr-09 2:01
Seishin#8-Apr-09 2:01 
GeneralRe: LOL Pin
Phylum12322-Oct-09 5:25
Phylum12322-Oct-09 5:25 
GeneralExceoption when trying to upload [modified] Pin
#realJSOP8-Jan-09 11:52
professional#realJSOP8-Jan-09 11:52 
QuestionHow to connect to two FTP Servers Pin
LearnNetnAll15-Dec-08 21:59
LearnNetnAll15-Dec-08 21:59 
GeneralA socket operation encountered a dead network Pin
josephx2k715-Dec-08 12:41
josephx2k715-Dec-08 12:41 
Generalgood library Pin
emilioarp12-Nov-08 7:30
emilioarp12-Nov-08 7:30 
Generalconnection was forcibly closed by the remote host at System.Net.Sockets. Pin
next100years11-Nov-08 0:55
next100years11-Nov-08 0:55 
GeneralA comfortable FTP class in .NET Pin
Elmue27-Aug-08 12:22
Elmue27-Aug-08 12:22 

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.