Access password protected shared network - c#

How to read/write files in a shared network drive?
I am creating an application to upload files to the password protected shared network drive. When I run locally, the files are uploaded well. But, in the publish environment it throws:
Access to the Path '/shared network drive/' is denied
How to resolve this ?

Two ways:
1) Create a network drive connection to the remote machine (so it appears to your computer as "X:" for example) and save to that.
2) Use the full UNC path specification: //RemoteMachineName/SharedFolder/foldername

Related

Accessing A shared network drive from a Microsoft Azure WebJob

I am trying to write a file to a location on a shared network drive on a remote server. When I run my code in my local environment, it works successfully and I can upload files. However, when running the code from an Azure WebJob, I get
Access to the path is denied
or
Access is denied
I am accessing the netwrok share using a method as posted here
and implementing as follows:
using (NetworkShareAccesser.Access(REMOTE_COMPUTER_NAME, DOMAIN, USER_NAME, PASSWORD))
{
File.WriteAllText(string.Format(#"{0}\TestFileName.csv", networkPath), sb.ToString());
}
As I say, if I run this on my local pc, it works and uploads the file. Something is different when running from an Azure WebJob. Is there some extra permission/ security required to access the shared drive from Azure?
Thanks in advance.

Read/write files in shared drive from web application hosted on iis

We have two server in same domain. On one server (SERVER1) we have folder "C:\AppFiles\Production\Inbound" and shared AppFiles folder as a drive (AppFiles (O:)) to another server (SERVER2) and we are manually able to place files in shared drive (O:\Production\Inbound) on SERVER2. But we want to read/write files in shared drive (O:\Production\Inbound) from our mvc web application hosted on SERVER2.
We are getting below error in provided code when try to read/write in shared drive (O:\Production\
public void Writefile()
{
System.IO.File.WriteAllText(Path.Combine(#"O:\Production\Inbound", "testlog.txt"), "test test, text");
}
error:
Could not find a part of the path 'O:\Production\Inbound\testlog.txt'.
Please suggest how i can read/write files in shared drive from application hosted on iis.
Mapped drives are not supported on IIS, rather you can use UNC paths. Try changing the path to the following:
\\SERVER1\C$\AppFiles\Production\Inbound
If both the servers are on the same network and you can access the above link from server 2, the it should work.

Accessing an NFS share from a Windows service

I have a Windows service that can't access an NFS share on a UNIX box. I can't access the share with the UNC path, so I have to have it mounted.
I have a console application that can see the drive and runs fine, but when I deploy my Windows service, it can't see the drive.
I have the drive mounted as my local user as well as the administrator.
I've tried mounting a drive from my application by using "Process.Start(mBatchFilePath);", but that didn't work either.
I'm running as the local user (set as administrator).
Tried using a symbolic link
Going to try to set up an FTP to transfer the files
Does anyone have any suggestions on how I can make this work?
SOLVED: I used SSH.Net and transfer files with an SFTP server
I don't think that mapping the drive to a symbolic link is a real solution. The Problem is, that the service runs under a certain user account and thus it accesses all resources with the privileges of this account. Of course your IT admin is right, it's not a good idea to let the service run under the local administrator account.
You should create a new user account that is allowed to access the shared folder. Then set up the service that it runs under this account and the service should be able to access the network share. But remember, a network share that is mapped to a drive letter is only mapped for the current user. So the service (that runs under a different user account) simply doesn't have any drive with this letter, it is not mapped under its account.
So in your service you should always access the share with its full UNC path and not with a mapped drive letter.
Since we were connecting to a Solaris server from a windows box I needed to use SFTP to send files to the server.
I contemplated some sort of a folder sync, but it wasn't a route I wanted to go down.
I used the SSH.Net libraries.

upload file to the network mapped drive in c#

I am using c# asp.net mvc 3 and entity framework to upload the file to the network drive mapped as Z drive. I have following c# code for determining file path:
var path = Path.Combine(Z:/upload/catone/", fileName);
aries.SaveAs(path);
I am using window server 2008 and IIS 7. I have also check Security of upload folder of network drive and have acess full control for EVERYONE user. If I changed file path to local drive, it works fine. But it shows following error while uploading to network drive (Z:/).
Could not find a part of the path
'Z:\upload\catone\_2013011504265221N_todaily.wav'.
Your code is running under IIS and thus is run with access privileges of the IIS user account which may not have access to that network drive.
You can try runnning the app pool under your identity for instance, to rule this issue out, or give full access to the group IIS_IUSRS to that folder.
First of all save the file in local machine ,
than after use file.copy(Source, Destination, true) method to save file in network drive.
try that it is helpful for you

How to map local drive to a remote server using C#

I need to distribute a local msi installer to a number of remote servers.
I assume, that the way to do it is to map my local drive (on which the msi is located) to those remote servers and then copy this file from the mapped local drive onto a specific directory of each server.
At firs, I was trying to copy file to a remote server without doing any prior mapping:
System.IO.File.Copy(#"\\WIN-J02JG3AAV7P\temp\emcrpts_x64_v40.msi",
#"\\sharepoint2010\C$", true);
this did not work (error: the network path was not found)
Then, I'm trying to map my local drive to a remote server, but I'm lacking the proper syntax.
If I have a local C:\temp shared, what is the proper C# syntax to map it to a remote server named "sharepoint2010"?
Appending a file name to the destination could already fix your problem:
File.Copy(#"\\WIN-J02JG3AAV7P\temp\emcrpts_x64_v40.msi",
#"\\sharepoint2010\C$\emcrpts_x64_v40.msi", true);
The destination can't be a directory, see the documentation.

Categories