Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File.Copy() to file server with network Credential [duplicate]

Tags:

c#

file-io

I am writing console application which will Copy file from my local disk to file server. This folder is protecting by username and password. File.Copy() method does not work. It gives permission error. I have looked to this code

I have tried it but it does not work. First it was written in VB but I have changed the code to C# but there are have some errors. I don't know what does this error mean. Maybe you can advise me other way coping file to protected File Server

with simple File.Copy(bla bla) it gives me "you have not permission"

when i converted VB code to C# it gived me error below: Attempted to read or write protected memory

I have found solution

You can Follow It

like image 600
AEMLoviji Avatar asked Feb 10 '11 13:02

AEMLoviji


People also ask

How do you give credentials in a batch script that copies files to a network location?

Try using the net use command in your script to map the share first, because you can provide it credentials. Then, your copy command should use those credentials.

Can t copy file from mapped drive?

It could be on a hard drive on this computer, or on a network. Check to make sure that the disk is properly inserted, or that you are connected to the Internet or your network, and then try again. If it still cannot be located, the information might have been moved to a different location.

How do I copy files over a network in Linux?

Once the ssh client software is installed you can use the scp command to connect and transfer files to/from the remote machine (the Raspberry Pi running the ssh server). The basic form of the command is scp , the source file name, then the destination file name.


1 Answers

You could use the little impersonation class I wrote some years ago:

using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) )
{
   // code that executes under the new context.
   File.Copy( x, y );
}
like image 171
Uwe Keim Avatar answered Sep 30 '22 14:09

Uwe Keim