Access Files on Ubuntu Machine from windows in C#

Last Reply on Jul 28, 2016 12:10 AM By ShaibaazS

Posted on Jul 11, 2016 02:24 AM

I want to access Files on Ubuntu system from a window system. Both the systems are in the same network. Is there a way to achieve the above using c#


Posted on Jul 28, 2016 12:10 AM Modified on on Jul 28, 2016 12:11 AM

Yes I will be posting the answer .

For time being for whom ever who comes accross this situation

  1. Configure a SFTP Server on Ubuntu Machine.
  2. In my case I have mapped Local IP to a Static IP for the Ubuntu machine by forwarding port "22" on  my router. Port "22" is the default port for configuring SFTP Server.
  3. I have added "Renci.SshNet" reference from NuGet Packet Manager. For I have to add the following namesapces.
    using Renci.SshNet;
    using Renci.SshNet.Common;
    using Renci.SshNet.Sftp;
  4. Also I have referred to the follwing Link:
  5. Please find the below Source Code for the same.
using System.IO;
using Renci.SshNet;
using Renci.SshNet.Common;
using Renci.SshNet.Sftp;
String Host = "";
int Port = 22;
String RemoteFileName = "TheDataFile.txt";
String LocalDestinationFilename = "TheDataFile.txt";
String Username = "yourusername";
String Password = "yourpassword";
using (var sftp = new SftpClient(Host, Port, Username, Password))
    using (var file = File.OpenWrite(LocalDestinationFilename))
        sftp.DownloadFile(RemoteFileName, file);

I hope this will help you.


Thanks .