Copying files using process class in ASP.NET

M

Mark

Hi all, I am trying to execute a batch file to copy over files from one
server to another. The batch file is using robocopy to copy over the files.
============
private void CopyFiles()
{// Use the process name space to copy over the files
System.Diagnostics.Process oProc = new System.Diagnostics.Process();

oProc.StartInfo.FileName ="c:\CopyFiles.bat" ;

oProc.Start();

}

============
When I run the above routine nothing gets copied and I get no error message
whatsoever.
When I manually run the batch file the copy works fine so it is not the
batch file.

Batch file is shown below..


robocopy c:\images \\remoteserver\c$\images /e
robocopy c:\documents \\remoteserver\c$\documents /e

I am assumming that it might be something to do with user permission
settings, ASPNET user has full rights on both the local machine as well as
the remote machine.

Any help appreciated.

Thanks in advance
Mark
 
S

Scott Allen

Hi Mark,

If the problem is permissions (and like you I'd suspect this also),
you won't get an exception. Instead, the process is probably
displaying an error message in the output stream.

Use the StartInfo property to setup StandardOutput and StandardError
for reading from your code:

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.RedirectStandardError = true;

Start the process then wait for the process to finish:

p.WaitForExit();

Then read the streams and look at what appears. Hopefully you'll find
an access denied message with some additional information.

If you need help tracking down who is getting an access denied message
on what, enable auditing and watch the security log:

http://www.pluralsight.com/keith/book/html/howto_auditfileaccess.html

HTH,
 
M

Mark

Hi Scott, thanks for that. I will give it a whirl and see how I get on

Thanks again
Mark
 
D

Dies Deambulo

I was able to do this in a window form but not in an asp.net form.
Perhaps the "user" that run the asp.net doesn't have permission to run
the process?

Robert
Hi Scott, thanks for that. I will give it a whirl and see how I get on

Thanks again
Mark

Bank of America defines chintzy IMHO.
Email for details.
Robert Megee
 
D

Dies Deambulo

Hi Scott,
Today I made the asp.net user an administrator. Still didn't run.
I'm beginning to believe that it just won't.
I'm working on doint this with tcpclient/tcplistener instead. I was
a bit afraid of it at first but now that I dove in, it may actually be
a better way to move data.

Robert


Hi Robert:

Nine times out of ten it is a permission issue.

Bank of America defines chintzy IMHO.
Email for details.
Robert Megee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top