TechSapphire Friday, 2018-09-21, 8:59 PM
Site menu
Login form
News
Play Games
  • Deep Freeze
  • Ice Slide
  • Gyroball
  • Fat Fish
  • Bush Royal Rampage
  • Uploading and downloading file on SFTP using private key in .NET using SharpSSH

    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();
            }
        }
    }

     

    To download project click here.

    Categories
    Programming [27]
    Tips for programming
    Security [2]
    Security Tips
    Google [1]
    Use google faster then ever you use
    Project [14]
    HTML [2]
    Electronics [0]
    Data Structure [0]
    Database [16]
    SQL SERVER
    SSRS [1]
    Sql Server Reporting Services
    Copyright MyCorp © 2018