Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# copy file to another directory using other domain/username/password

In c# 2008, I'm trying to copy a file to a destination path (for example \newserver\destinationFolder), that can be in another domain or using a different username/password than the current user. How can I specify these new network credentials before doing the File.Copy(...) ?

Thank you!

like image 306
Cedric Avatar asked Apr 30 '10 13:04

Cedric


2 Answers

Good question but I dont think this is possible. I believe this type of file copy from one domain to another ( where there is not a trust set up) would be considered security hole.

Some options:

  1. Set up a trust between the domains and give rights to the current user
  2. You could try a Shell execute command and see if you can make this work through command line parameters. I was thinking "Net use" command.
like image 199
John Hartsock Avatar answered Sep 22 '22 06:09

John Hartsock


Look at LogonUser. Here's the pinvoke page for it:

http://www.pinvoke.net/default.aspx/advapi32.logonuser

like image 42
Hans Olsson Avatar answered Sep 26 '22 06:09

Hans Olsson