HI there
First time poster, long time lurker
I am building a windows class library that will be used on an active
server page. The purpose of the library is to copy files from one
server to another. The number of files to be copied will range
anywhere from 1 to 1000. Seems simple enough, but here's the catch:
the code will be running in domain A and the source files will need to
be copied from Domain B to Domain C. My issue is authentication. I
have tinkered with using the Diagnostics.Process class to run "net
use" commands to connect to the shares on Domains B and C (See
OpenShare method below). The OpenShare function runs just fine and
the "net use" returns with an ExitCode of 0. So, everyhting should be
OK. However, when I attempt to copy files between the shares using
File.Copy, I get "Access Denied" errors. It is as if the shares were
not created. I know that the permissions of the domain users I am
using are sufficient to perform the required operations. Also, the
IUSR that is running the code will be priviledged enough to run
cmd.exe (I know, that may give some heart palpatations, but there are
several other layers of security in place). Any thoughts, ideas, and
criticisms are welcome.
string retval1 = OpenShare(@"\\domainB\shareB", "userBpassword",
"domainB\userB");
string retval2 = OpenShare(@"\\domainC\shareC", "userCpassword",
"domainC\userC");
// retval1 and retval2 should each be "0";
try
{
File.Copy(@"\\domainB\shareB\myfile.txt",
@"\\domainC\shareC\myfile.txt", true);
}
catch(System.Exception err)
{
// Do stuff to handle errors...
// err.Message will contain "Access Denied"
}
private string OpenShare(string username, string password, string
uncpath)
{
try
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.Arguments = String.Format("/c net use {0} {1} /user:{2}",
uncpath, password, username);
Process proc = Process.Start(psi);
proc.WaitForExit();
return "(OpenShare) " + Convert.ToString(proc.ExitCode);
}
catch(System.Exception err)
{
return err.Message;
}
}