Access Files on Ubuntu Machine from windows in C#

ShaibaazS
 
on Jul 11, 2016 02:24 AM
5300 Views

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 asp.net c#

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
ShaibaazS
 
on Jul 13, 2016 06:57 AM

Dear Dharmendr,

I have already gone through the links before and are not much of a use in my case.

But above all i really appreciate your help & support.

Thanks.

 

ShaibaazS
 
on Jul 25, 2016 06:01 AM

Dear All,

 

I have achieved the same by using SFTP instead of FTP .

I dont know why it was not happening using FTP .

But through SFTP I achieved it.

Thanks.

dharmendr
 
on Jul 25, 2016 06:32 AM

Hi ShaibaazS,

As you have solved by your self, so please share the solution with us so this can be beneficial to other community members reading the thread.

ShaibaazS
 
on Jul 28, 2016 12:10 AM
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: http://www.csidata.com/?page_id=2828
  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 = "ftp.csidata.com";
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))
{
    sftp.Connect();
 
    using (var file = File.OpenWrite(LocalDestinationFilename))
    {
        sftp.DownloadFile(RemoteFileName, file);
    }
 
    sftp.Disconnect();
}

I hope this will help you.

 

Thanks .