How we can Transfer File from Windows to Ubuntu viceversa using C#

Step1: Download and Extract the SharpSSH-1.1.1.13.bin.zip
SharpSSH-1.1.1.13.bin.zip/download
Step2: Add these files  DiffieHellman.dll,Org.Mentalis.Security.dll,Tamir.SharpSSH.dll to Reference
Step3: Using following :
using Tamir.SharpSsh;
using Tamir.Streams;

C# Code
---------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tamir.SharpSsh;
using Tamir.Streams;
using System.IO;

namespace consoleLinuxcon
{
    class Program
    {
        static void Main(string[] args)
        {
            string hostname = "IPAddressof UbuntuServer";
            string user = "UserName";
            string password="password";
            string SourcePath=@"C:\test";
            string DestPath=@"/Home/path/";

            Sftp sftp = new Sftp(hostname, user,password);

            sftp.Connect();
        
            sftp.Put(SourcePath,DestPath ); // From Windows to Ubuntu
             sftp.Get(DestPath, SourcePath); //From Ubuntu to Windows

            sftp.Close();

        }
    }
}

No comments:

Post a Comment