Click here to Skip to main content
11,479,170 members (44,928 online)
Click here to Skip to main content

C# FTP Client Library

, 23 May 2007 CPOL 175.8K 3.1K 124
Rate this:
Please Sign up or sign in to vote.
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):

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)

Share

About the Author

jmers
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

 
QuestionThank you Pin
Jason asdf29-Apr-14 12:52
memberJason asdf29-Apr-14 12:52 
QuestionHow to check if the connection is established? Pin
AnLa06109527-Jun-11 5:08
memberAnLa06109527-Jun-11 5:08 
GeneralAlex FTPS Client Pin
B.Ritter5-Mar-11 1:09
memberB.Ritter5-Mar-11 1:09 
Generalexpect a demo Pin
pclion13-Feb-11 23:55
memberpclion13-Feb-11 23:55 
GeneralNot work in download .. Pin
AlexB4712-Feb-11 8:33
memberAlexB4712-Feb-11 8:33 
GeneralBug solutions Pin
robnet17-Aug-10 1:28
memberrobnet17-Aug-10 1:28 
GeneralRe: Bug solutions Pin
B.Ritter1-Nov-10 7:37
memberB.Ritter1-Nov-10 7:37 
QuestionI cannot get the listing of the files plus other bugs Pin
Evandrojr2-Mar-10 11:22
memberEvandrojr2-Mar-10 11:22 
I have tried with 2 different servers.

It connects but then says that there are 0 files and when I try to download a file it says it could not be found.

namespace NeoUpdate.Core
{
    public class UpdateItSelf
    {
        public void CheckForUpdate()
        {
            OpenFTP.FTP f = new OpenFTP.FTP();
 
            f.Connect("xxxxxx", "xxxxx", "xxxxx");
 
            //Gets an exception wrong date time
            //            f.ChangeDirectory("/"); 

            // is ok
            string dir = f.Directories.GetWorkingDirectory();
            string fileNames;
 
            f.Files.RebuildFileList();
 
            //  f.Files.Count is always = ZERO
            for( int i=0; i <  f.Files.Count; ++i){
                fileNames = f.Files[i].FileName;
            }
 
            //gets an exception (file not found)
            f.Files.Download("n.txt");

GeneralActive Mode Pin
liglio27-Jan-10 15:33
memberliglio27-Jan-10 15:33 
GeneralRe: Active Mode Pin
jmers27-Jan-10 18:13
memberjmers27-Jan-10 18:13 
GeneralRe: Active Mode Pin
liglio28-Jan-10 4:13
memberliglio28-Jan-10 4:13 
GeneralRe: Active Mode Pin
Daniel Castenholz29-Jan-10 9:22
memberDaniel Castenholz29-Jan-10 9:22 
QuestionSocketException Error Code 11004 Pin
Zac Greve10-Jan-10 11:54
memberZac Greve10-Jan-10 11:54 
AnswerRe: SocketException Error Code 11004 Pin
jmers10-Jan-10 16:18
memberjmers10-Jan-10 16:18 
Questionupload folder Pin
Direkt200718-Nov-09 5:07
memberDirekt200718-Nov-09 5:07 
GeneralCF 3.5 Pin
Gateone7512-Aug-09 3:32
memberGateone7512-Aug-09 3:32 
RantLOL Pin
Seishin#8-Apr-09 3:01
memberSeishin#8-Apr-09 3:01 
GeneralRe: LOL Pin
Phylum12322-Oct-09 6:25
memberPhylum12322-Oct-09 6:25 
GeneralExceoption when trying to upload [modified] Pin
John Simmons / outlaw programmer8-Jan-09 12:52
mvpJohn Simmons / outlaw programmer8-Jan-09 12:52 
QuestionHow to connect to two FTP Servers Pin
LearnNetnAll15-Dec-08 22:59
memberLearnNetnAll15-Dec-08 22:59 
GeneralA socket operation encountered a dead network Pin
josephx2k715-Dec-08 13:41
memberjosephx2k715-Dec-08 13:41 
Generalgood library Pin
emilioarp12-Nov-08 8:30
memberemilioarp12-Nov-08 8:30 
Generalconnection was forcibly closed by the remote host at System.Net.Sockets. Pin
next100years11-Nov-08 1:55
membernext100years11-Nov-08 1:55 
GeneralA comfortable FTP class in .NET Pin
Elmue27-Aug-08 13:22
memberElmue27-Aug-08 13:22 
GeneralChangeDirectory Chrash Pin
Member 42541521-May-08 12:52
memberMember 42541521-May-08 12:52 
GeneralRe: ChangeDirectory Chrash Pin
jmers3-May-08 10:36
memberjmers3-May-08 10:36 
GeneralRe: ChangeDirectory Chrash Pin
streit31-May-08 14:13
memberstreit31-May-08 14:13 
GeneralRe: ChangeDirectory Chrash Pin
emilioarp2-Oct-08 9:47
memberemilioarp2-Oct-08 9:47 
GeneralRe: ChangeDirectory Chrash Pin
B.Ritter3-Nov-08 10:50
memberB.Ritter3-Nov-08 10:50 
GeneralRe: ChangeDirectory Chrash [modified] Pin
B.Ritter8-Nov-08 3:42
memberB.Ritter8-Nov-08 3:42 
GeneralRe: ChangeDirectory Chrash Pin
emilioarp10-Nov-08 9:18
memberemilioarp10-Nov-08 9:18 
GeneralRe: ChangeDirectory Chrash Pin
B.Ritter10-Nov-08 23:12
memberB.Ritter10-Nov-08 23:12 
GeneralRe: ChangeDirectory Chrash Pin
emilioarp12-Nov-08 5:24
memberemilioarp12-Nov-08 5:24 
GeneralRe: ChangeDirectory Chrash Pin
jose.mira27-Apr-09 8:38
memberjose.mira27-Apr-09 8:38 
GeneralRe: ChangeDirectory Chrash Pin
jose.mira4-May-09 8:01
memberjose.mira4-May-09 8:01 
Generalerror connecting the ftpserver Pin
nanio31-Jan-08 21:56
membernanio31-Jan-08 21:56 
GeneralRe: error connecting the ftpserver Pin
jmers30-Apr-08 6:57
memberjmers30-Apr-08 6:57 
GeneralSubdirectories when uploading Pin
dannywooly21-Nov-07 1:50
memberdannywooly21-Nov-07 1:50 
GeneralRe: Subdirectories when uploading Pin
jmers21-Nov-07 5:24
memberjmers21-Nov-07 5:24 
GeneralFiles download Pin
blablablaidan24-Oct-07 23:05
memberblablablaidan24-Oct-07 23:05 
GeneralRe: Files download Pin
jmers25-Oct-07 2:13
memberjmers25-Oct-07 2:13 
GeneralRe: Files download Pin
blablablaidan25-Oct-07 4:09
memberblablablaidan25-Oct-07 4:09 
GeneralRe: Files download Pin
jmers25-Oct-07 4:43
memberjmers25-Oct-07 4:43 
GeneralRe: Files download Pin
blablablaidan25-Oct-07 5:15
memberblablablaidan25-Oct-07 5:15 
GeneralRe: Files download Pin
jmers30-Apr-08 7:02
memberjmers30-Apr-08 7:02 
GeneralRe: Files download Pin
G_Pow18-Sep-08 12:39
memberG_Pow18-Sep-08 12:39 
GeneralRe: Files download Pin
emilioarp12-Nov-08 8:23
memberemilioarp12-Nov-08 8:23 
GeneralRe: Files download Pin
Member 45941477-Apr-09 16:40
memberMember 45941477-Apr-09 16:40 
GeneralList Directories Pin
blablablaidan17-Oct-07 2:58
memberblablablaidan17-Oct-07 2:58 
GeneralRe: List Directories Pin
jmers24-Oct-07 6:38
memberjmers24-Oct-07 6:38 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 23 May 2007
Article Copyright 2007 by jmers
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid