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

mitesh patel 6 Reputation points
2022-01-26T12:39:55.653+00:00

Hi,

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.

C#
C#
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.
10,247 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Castorix31 81,726 Reputation points
    2022-01-26T12:51:22.173+00:00

    There is WinSCP

    0 comments No comments

  2. Michael Taylor 48,281 Reputation points
    2022-01-26T15:51:35.577+00:00

    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.

    0 comments No comments

  3. Jack J Jun 24,286 Reputation points Microsoft Vendor
    2022-01-27T06:26:58.08+00:00

    @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.

    0 comments No comments

  4. Hans Milling 5 Reputation points
    2023-01-18T13:18:31.7633333+00:00

    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);
    client.Delete("/documents/document1.docx");
    client.Disconnect();
    client.Dispose();

    0 comments No comments