Copy files between servers

C

Chris Strobel

I have 2 web servers where I need to write a PDF file and need to keep them
in sync. In others words, If the Server1 is getting called to create the
PDF, then it needs to copy the PDF to the other Server2 and visa-versa. The
2 server are running 2003.

It's a form-based authentication (.NET 1.1) site and I'm using IIS 6 native
mode. Both boxes are set to the same workgroup. Since everything is so
locked down now, I'm not sure what's the best way to copy files to another
server from within a VB ASPX page. I've seen some sample impersonation code
but it seems like there would be an easier way.

Thanks,
Chris
 
R

Raterus

File.Copy("\\Server1\share\file.abc", "\\Server2\share\file.abc", true)

But before you can do this, you are going to have to impersonate a valid domain user that can perform this operation. This can be done via web.config using

<identity impersonate="true" userName="DOMAIN\bob" password="mypassword" />

But if you don't want your entire application running as this user (I woudln't), you can impersonate via code with examples from this article (you would need to use second way if you have a specific user that you want to use), or the first article if you are using credentials from the authenticated client.

http://support.microsoft.com/default.aspx?scid=kb;en-us;306158

Hope this helps,
--Michael
 
C

Chris Strobel

Thanks for the reply Michael...

Is there no way to just have each box trust the other or give the
appropriate rights to each dll assembly?

It seems odd with .NET, that to copy a file between web servers I have to
have 40 or so lines of impersonation code.

Thanks,
Chris

File.Copy("\\Server1\share\file.abc", "\\Server2\share\file.abc", true)

But before you can do this, you are going to have to impersonate a valid
domain user that can perform this operation. This can be done via
web.config using

<identity impersonate="true" userName="DOMAIN\bob" password="mypassword" />

But if you don't want your entire application running as this user (I
woudln't), you can impersonate via code with examples from this article (you
would need to use second way if you have a specific user that you want to
use), or the first article if you are using credentials from the
authenticated client.

http://support.microsoft.com/default.aspx?scid=kb;en-us;306158

Hope this helps,
--Michael
 
R

Raterus

You mentioned workgroup? Is there really not a domain in this situation? If that is the case, I don't think you can even use impersonation. How does your IIS server sit inside this workgroup? is it one of these two servers? Have you tried just the file.copy code and see what happens?
 
W

William F. Robertson, Jr.

The way we resolved this issue is create a user account on each web server
machine with the passwords manually syncronized. The have the Application
Pool in IIS 6.0 run under that account. Each account having the same
username and password, will enable write access.

Can you not just save this file in one location and have both servers pull
from this one location?

HTH,

bill
 
S

Scott Allen

As another option In a workgroup, one could create matching accounts
on both servers.
 
C

Chris Strobel

Both web servers will sit in a DMZ with same workgroup, separate from the
domain. If I try file.copy I get permission errors. I tried having one box
trust the other assembly and get:

Logon failure: unknown user name or bad password.

Thanks,
Chris

You mentioned workgroup? Is there really not a domain in this situation?
If that is the case, I don't think you can even use impersonation. How does
your IIS server sit inside this workgroup? is it one of these two servers?
Have you tried just the file.copy code and see what happens?
 
C

Chris Strobel

Hi Bill,

Wouldn't we have the same permission problem if there was another server
that both Web servers wrote the file to?

I'll try looking at the application pool account.

Thanks,
Chris
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top