Click here to Skip to main content
13,629,039 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


22 bookmarked
Posted 7 Jul 2016
Licenced CPOL

Upload File to SFTP Site with C# in Visual Studio .NET

, 7 Jul 2016
Rate this:
Please Sign up or sign in to vote.
How to Use SSH.NET in Visual Studio 2015 to upload a file to an SFTP site


This is a simple solution for uploading files to an SFTP server from .NET Framework using Visual Studio 2015.

The SSH package offers many more options that can be explored. For the purposes of this tip, I am only concentrating on a simple file transfer from a local server to an SFTP site (Upload).


After searching for 2 days, I finally came across a solution out of Belgium that allowed me to programmatically upload a file to an SFTP server. There is not a lot of documentation out there on the use of SSH.Net, so I hope you find this useful. Credit to for the original posting of this fix. Since so many of my colleagues utilize Code Project, I felt it would be a good location to add this information.

Using the Code

In your Solution / Project:

Select Manage NuGet Packages and search for and select SSH.Net --> Install Latest Stable Version (2013.4.7) supports .NET 3.5 and 4.0

Add New Blank Class to your project - then add the following code to your class.

using Renci.SshNet;
using System.IO;

namespace YourProjectNamespace
 class sftp
  public static void UploadSFTPFile(string host, string username, 
  string password, string sourcefile, string destinationpath, int port)
   using (SftpClient client = new SftpClient(host, port, username, password))
    using (FileStream fs = new FileStream(sourcefile, FileMode.Open))
     client.BufferSize = 4 * 1024;
     client.UploadFile(fs, Path.GetFileName(sourcefile));


In your event call, pass the needed parameters for your file to upload:

string source = @"FilePath and FileName of Local File to Upload";
string destination = @"SFTP Server File Destination Folder";
string host = "SFTP Host";
string username = "User Name";
string password = "password";
int port = 22;  //Port 22 is defaulted for SFTP upload

sftp.UploadSFTPFile(host, username, password, source, destination, port);


  • 7th July, 2016: Initial version


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


About the Author

United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionHow to do retry if initial connection fails and closed in the midway? Pin
Ch Smrutiranjan22-Jun-18 1:32
memberCh Smrutiranjan22-Jun-18 1:32 
QuestionError with connection Pin
Member 129069616-Mar-18 14:28
memberMember 129069616-Mar-18 14:28 
QuestionMessage Removed Pin
11-Jul-17 1:01
membertech360.ats11-Jul-17 1:01 
QuestionSFTP Pin
sivaram61910-Feb-17 0:21
membersivaram61910-Feb-17 0:21 
AnswerRe: SFTP Pin
sjelen10-Feb-17 2:56
membersjelen10-Feb-17 2:56 
GeneralMy vote of 5 Pin
pkbrauner13-Dec-16 0:56
memberpkbrauner13-Dec-16 0:56 
QuestionNice work. Pin
TimoKinnunen8-Jul-16 3:39
memberTimoKinnunen8-Jul-16 3:39 
SuggestionWinSCP Assembly Pin
Kevin Straßer8-Jul-16 1:41
professionalKevin Straßer8-Jul-16 1:41 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180712.1 | Last Updated 7 Jul 2016
Article Copyright 2016 by slccocdev
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid