svdl,
Thanks for the quick reply.
I had considered both of these options.
I would rather not use the 'net use' option because I may want to allow people to locate the shares via a GUI interface.
I had really hoped to find a way to copy the files "point to point" rather that source-to-me, me-to-target. It seems odd to be able to do something in DOS/CMD that I am unable to do in C#.Net.
If no one can suggest a better way, I will use the first method and award points to you.
Thanks.
Bryan Hunt
Main Topics
Browse All Topics





by: svdlPosted on 2008-09-08 at 21:32:20ID: 22424300
If you don't mind staging the files to be copied on your workstation, here's how you can do it:
tPrincipal Policy(Pri ncipalPoli cy.Windows Principal) ;
passwordB) ; passwordC) ;
t context = fromIdentity.Impersonate() ;
nate();
- set the PrincipalPolicy of the AppDomain to WindowsPrincipal:
AppDomain.CurrentDomain.Se
Then create two WindowsIdentity objects, one with a username/password that's valid in the domain you want to copy the files FROM and one with a username/password that's valid in the domain you want to copy TO:
WindowsIdentity fromIdentity=new WindowsIdentity(usernameB,
WindowsIdentity toIdentity=new WindowsIdentity(usernameC,
Impersonate the fromIdentity and copy the files:
WindowsImpersonationContex
DoCopyFiles(serverB, localmachine); // method to copy the files to your workstation, not shown here
Stop impersonating, then impersonate the toIdentity and copy the files out to domain C:
context.Undo();
context=toIdentity.Imperso
DoCopyFiles(localmachine, serverC);
context.Undo() //resume your original identity
Another, far simpler way would be generating a simple batch file that maps drives using username/password combinations that are valid for domain B resp domain C:
net use y: \\serverB\shareB passwordB /USER:domainB\userB
net use z: \\serverC\shareC passwordC /USER:domainC\userC
run the batch file from C#, and then copy the files from y:\ to z:\
Don't forget to clean up the shares after use!