Facebook

Topic to cover:

Connecting SFTP using Private Key using .NET console App
• Downloading and Uploading File

For complete SFTP operation in detail check link below:
Article: http://www.techsapphire.in/index/sftp_download_upload_and_delete_file_using_sharpssh_library/0-150
Video: https://youtu.be/VVqh0BCgFpM

Library used Sharpssh. To install:

• Got to Tools:>Library Package Manager:>Manage NuGet Pankages for solutions

• Search SharpSSh

• Install

Script:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tamir.SharpSsh;
using System.Collections;
using System.Windows.Forms;
using System.IO;
using Tamir.SharpSsh.jsch;
namespace SFTPConnectSample
{
    class Program
    {
        static void Main(string[] args)
        {


            string _privateSshKeyPath = @"D://Key//yogesh.key";
            Sftp sftp = new Sftp(SFTPConnectSample.Properties.Settings.Default.HostName, SFTPConnectSample.Properties.Settings.Default.UserName);
            sftp.AddIdentityFile ( _privateSshKeyPath);
            sftp.Connect();
            ArrayList res = sftp.GetFileList(".");
            //upload a file
            sftp.Put(@"D://txtfilesevice.txt", "txtfilesevice.txt");
            //download a file
            sftp.Get("a.xml", @"D://Key//hello.txt");
            ArrayList Newres = sftp.GetFileList(".");
            sftp.Close();
        }
    }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *