DustineTheGreat
DustineTheGreat

Reputation: 77

.net - Access Linux directory with C# Windows Service

I still haven't started this yet - just want to get some ideas, but can I access the directories and files on a Linux machine within a network using a C# Windows Service? I've read this and this, but so far, they are only trying to fetch the files inside the directory. My goal is:

I've read something about SSH and FTP libraries for C#, but isn't it only for getting the files? I want to interact with the files itself inside the directory.

Any helpful links or answers will be appreciated.

UPDATE:

I think one of the requirements is no using of Active Directory - which cancels out use of Samba.

Upvotes: 0

Views: 3405

Answers (2)

AirPett
AirPett

Reputation: 1014

Samba setup guide

First update the server and install Samba:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install samba

Then wget this file: Samba config. Open it with your favorite text editor (i.e. nano on vi). REMEMBER TO SUDO THE EDITOR!!!

Find the following lines (and change the parameters to suit your needs):

[share]
   comment = A share
   path = /path/to/folder
   browsable = yes
   guest ok = no
   read only = no
   create mask = 0755

comment is a description for the share.

path is the path to the folder to share

browsable = yes makes the share and it's content browsable for authenticated users

guest ok = no disables anonymous login

read only = no enables editing and renaming files

create mask = 0755 sets the default permissions for new files


Then create user (and set password) for accessing the share:

sudo useradd share
sudo passwd share
sudo smbpasswd -a share
sudo smbpasswd -e share

Move your smb.conf to /etc/samba/smb.conf

sudo mv smb.conf /etc/samba/smb.conf

Reload Samba config:

sudo /etc/init.d/samba reload

OR If that doesn't work:

sudo smbd reload

Done!

Now you can access the share on windows using \\serverAddress\share

The username is WORKGROUP\share OR linuxServerHostname\share and password is the password you set above.

You can now map the share as network drive into Windows by going to explorer and use the "Map Network Drive"-wizard. There tick the checkbox "Connect using different credentials". You can map the network drive with C# as well.

All files and folders in the share now (when mapped) act as local files.

Upvotes: 1

AirPett
AirPett

Reputation: 1014

Please make a Samba share on the remote Linux-machine, then the directory will act as a Windows share. Then you'd also be able to map it as a network drive and work with it the same way as local files.

Upvotes: 0

Related Questions