SFTP/FTP Operations from C# (.net framework 4.6.2)

mitesh patel 1 Reputation point


I'm looking for best practices/open source solutions to implement SFTP/FTP operations like below using C# (.Net framework 4.6.2) -

  1. Upload file(s) to SFTP/FTP server
  2. Download file(s) from SFTP/FTP server
  3. Delete file(s) from SFTP/FTP server

Would like to know what are the different options (Nuget packages/libraries etc..). Also would prefer if there are out-of-the-box libraries from Microsoft for the same.

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,567 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Castorix31 68,856 Reputation points

    There is WinSCP

  2. Michael Taylor 41,191 Reputation points

    FTP requests go through the same types as HTTP via the FtpWebRequest type. This is a low level wrapper around the FTP calls. A full example is provided in the link provided. This type is built into the framework and therefore you don't need anything else.

    However many people find the library to be limiting as it is really low level and based upon WebRequest which tries to normalize all network calls. As such it can be difficult to work with. Many people switch to a more powerful FTP library that can be downloaded from Nuget. FluentFtp is very popular but I have no experience with it. I find this site to be useful for figuring out the most popular Nuget packages but you still should evaluate each one for your specific requirements.

  3. Jack J Jun 21,976 Reputation points Microsoft Vendor

    @mitesh patel , Based on my search, I find some useful links I have done related to your question.

    Upload file: How to upload files with .db format from a remote server to a local server?

    Download file: Unable to delete files from a remote directory with SFTP?

    Delete file:Unable to delete files from a remote directory with SFTP?

    For their differences, please install nuget package SSH.NET if you want to do some oprations in SFTP.

    Please use the System.Net in your app if you want to use FTP.

    Hope my explanation could be helpful for you.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

  4. Hans Milling 0 Reputation points

    Use the SSH.NET NuGet package. This can do everything you need.
    var client = new SftpClient("<ip/dns>", 22, username, password); // You can aslo use a private key file
    client.UploadFile(stream, "/documents/document1.docx");
    client.DownloadFile("/documents/document2.docx", stream);