101

Can you recommend a free FTP library(class) for C#.

The class has to be well written, and have good performance.

Josef Van Zyl
  • 915
  • 3
  • 19
  • 43

7 Answers7

86

You may consider FluentFTP, previously known as System.Net.FtpClient.

It is released under The MIT License and available on NuGet (FluentFTP).

Erwin Mayer
  • 18,076
  • 9
  • 88
  • 126
  • 8
    THANK YOU!!! This really works very well! it lists directory with correct date time :)))) and its fast! sample code: FtpClient ftp = new FtpClient(txtUsername.Text, txtPassword.Text, txtFTPAddress.Text); `FtpListItem[] items = ftp.GetListing();//here you can get list with type, name, modified date and other properties. FtpFile file = new FtpFile(ftp, "8051812.xml");//file to get file.Download("c:\\8051812.xml");//download file.Name = "8051814.xml";//change name to get new file.Download("c:\\8051814.xml"); ftp.Disconnect();//close` – Zviadi Feb 16 '12 at 19:51
  • 1
    Note that the compiled libraries are for .NET 3 but the code is trivial to convert to 2.0 – Deanna Nov 07 '12 at 13:45
  • 3
    Is is also available als NuGet package: System.Net.FtpClient – Jeroen K Jun 11 '13 at 13:27
  • 2
    True, but you can easily add your own extension methods to have the same syntax as before. Here are mine: http://pastebin.com/FiKMrH76 – Erwin Mayer Jun 14 '13 at 09:27
  • 2
    While FluentFTP is indeed a good .NET FTP client library, it unfortunately does not support TLS/SSL session reuse. What is a severe limitation nowadays, when security is a must and many FTP server require the reuse. See [Can connect to FTP using FileZilla or WinSCP, but not with FtpWebRequest or FluentFTP](https://stackoverflow.com/q/65636482/850848). – Martin Prikryl Feb 04 '21 at 07:50
21

Why don't you use the libraries that come with the .NET framework: http://msdn.microsoft.com/en-us/library/ms229718.aspx?

EDIT: 2019 April by https://stackoverflow.com/users/1527/ This answer is no longer valid. Other answers are endorsed by Microsoft.

They were designed by Microsoft who no longer recommend that they should be used:

We don't recommend that you use the FtpWebRequest class for new development. For more information and alternatives to FtpWebRequest, see WebRequest shouldn't be used on GitHub. (https://learn.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest?view=netframework-4.7.2)

The 'WebRequest shouldn't be used' page in turn points to this question as the definitive list of libraries!

0fnt
  • 8,211
  • 9
  • 45
  • 62
  • 3
    Im not 100% sure but doesn't those classes reconnect on each request? If that is the case then the performance would suffer.. – Peter Jul 26 '12 at 16:01
  • 22
    The `FtpWebRequest` class only really works for simple, transactional FTP actions that can be modelled on the Request/Response pattern, such as downloading or uploading individual files. It's very difficult to use it to perform tasks like creating an FTP folder structure or upload and download in the same session. – Dai Sep 14 '12 at 18:16
  • They require a lot of "plumbing" including parsing each response. It's a good start, but it's incomplete. – James Mar 05 '13 at 16:25
  • 1
    "Should" is the operative word. It probably isn't worth your time to debug FtpWebRequest examples that only work in your unit tests. – CZahrobsky Jul 15 '14 at 20:05
  • There are apparently bugs (sorry for lack of source) in FtpWebFequest that cause issues when used with Mono .NET – Carlos P Oct 15 '14 at 17:48
  • 1
    Very... Bad component - you can't easy list files or folders, if you provide bad url - it will run without any exception, but will return html with message - I don't found any file (so, you need to parse that html)... I think microsoft can spend some time and create normal library and not this... – VikciaR Jun 11 '15 at 12:05
  • @VikciaR : Good news! You can contribute to the development on github now! :-) – 0fnt Jun 11 '15 at 14:29
  • 1
    @0fnt: Your comment is like: you don't like this car - make yourself. – VikciaR Jun 16 '15 at 06:19
  • `FtpWebRequest` still support only Explicit SSL. If you have to use Implicit SSL `FtpWebRequest` is not an option. – Johnny Jun 06 '17 at 09:03
  • 6
    The MS documentation https://learn.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest?view=netframework-4.7.2 says not to use for new projects, and points to https://github.com/dotnet/platform-compat/blob/master/docs/DE0003.md which in turn points to this question – Pete Kirkham Apr 08 '19 at 10:20
12

edtFTPnet is a free, fast, open source FTP library for .NET, written in C#.

Bruce Blackshaw
  • 986
  • 1
  • 7
  • 10
  • 1
    It's under LGPL license. So if you're developing commercial product/service you're opening that can of worms of what you can do and what you can't, what to include, etc. And multiple answers on SO and others give different opinions on that matter... – Oleksii Vynnychenko Nov 07 '16 at 08:35
  • 1
    I'm one of the developers of this software. I thought I'd just chip in that we've never pursued anyone over LGPL violations or even thought to look for any such cases. The main reason we chose this license when the library was first published in 2003 was that LGPL was one of the only such widely known licenses around. There are many more options now and we should probably find another license that better suits our aim. The only thing we want to ensure is that no one uses our software to create a commercial product that competes with it. Anyone got suggestions for a less onerous license? – HansA Mar 06 '17 at 04:46
  • 2
    By the way, if your legal people are ever worried about it, you can just purchase a more liberal license for $99. Oh, and also the website has been updated now :). The product is still very much alive, partly because it's a part of another very successful product, i.e. CompleteFTP. Thanks Oleksii for pointing out this problem. We'll discuss it. – HansA Mar 06 '17 at 04:48
7

I like Alex FTPS Client which is written by a Microsoft MVP name Alex Pilotti. It's a C# library you can use in Console apps, Windows Forms, PowerShell, ASP.NET (in any .NET language). If you have a multithreaded app you will have to configure the library to run syncronously, but overall a good client that will most likely get you what you need.

John C
  • 880
  • 10
  • 13
5

You could use the ones on CodePlex or http://www.enterprisedt.com/general/press/20060818.html

Kane
  • 16,471
  • 11
  • 61
  • 86
1

After lots of investigation in the same issue I found this one to be extremely convenient: https://github.com/flagbug/FlagFtp

For example (try doing this with the standard .net "library" - it will be a real pain) -> Recursively retreving all files on the FTP server:

  public IEnumerable<FtpFileInfo> GetFiles(string server, string user, string password)
    {
        var credentials = new NetworkCredential(user, password);
        var baseUri = new Uri("ftp://" + server + "/");

        var files = new List<FtpFileInfo>();
        AddFilesFromSubdirectory(files, baseUri, credentials);

        return files;
    }

    private void AddFilesFromSubdirectory(List<FtpFileInfo> files, Uri uri, NetworkCredential credentials)
    {
        var client = new FtpClient(credentials);
        var lookedUpFiles = client.GetFiles(uri);
        files.AddRange(lookedUpFiles);

        foreach (var subDirectory in client.GetDirectories(uri))
        {
            AddFilesFromSubdirectory(files, subDirectory.Uri, credentials);
        }
    }
Stephan
  • 1,639
  • 3
  • 15
  • 26
  • flagftp uses the Windows ftp client calls. This is not a good or bad thing but it does mean that the library is susceptible to the same errors that the windows ftp calls can throw – John Mott Jan 01 '15 at 16:21
  • 1
    They do not disclose a license. Last version 0.1.3 from 2012. This is a dead, incomplete, unlicensed project. – Kissaki Apr 08 '22 at 08:36
1

I've just posted an article that presents both an FTP client class and an FTP user control.

They are simple and aren't very fast, but are very easy to use and all source code is included. Just drop the user control onto a form to allow users to navigate FTP directories from your application.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
  • Uses the obsolete [FtpWebRequest](https://learn.microsoft.com/en-us/dotnet/api/system.net.ftpwebrequest?view=net-6.0#remarks) – Kissaki Jun 02 '22 at 10:01
  • 1
    @Kissaki: That's what can happen in answers that are over 11 years old. – Jonathan Wood Jun 03 '22 at 03:31
  • What a shame this is closed due to "This question does not meet Stack Overflow guidelines." It needs updating very badly, as this issue has grown even more widely known and urgent. See https://github.com/dotnet/runtime/issues/27916 (updated through Nov 2020) which points to this 2018 post https://github.com/dotnet/platform-compat/blob/master/docs/DE0003.md which as noted above points HERE to this thread that's "dead" but useful enough for the .NET Core team to leave a pointer to it? – M.Bearden Aug 19 '22 at 21:11