Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FileSystemObject - Copying files to mapped network drive

Posted on 2004-09-30
28
Medium Priority
?
3,828 Views
Last Modified: 2012-05-05
Hi Guys,

I have an asp page that is meant to copy a file from one server to another (the servers are identical, with requests managed by a load-balancer), both run Windows Server 2003 with IIS 6.0. When a user uploads a file, I need a copy of the file to be placed on the other server straight away.

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "D:\folder\file.ext", "G:\folder\file.ext"
Set objFSO = Nothing

G: is a mapped network drive onto the other server, and the above code returns 'Path not found'. Anybody got any ideas? Any help much appreciated.
0
Comment
Question by:jEd
  • 8
  • 5
  • 4
  • +3
28 Comments
 
LVL 15

Expert Comment

by:Thogek
ID: 12192259
Using Windows Explorer on the Web server in question, can you view "D:\folder\" and "G:\folder\" to verify that both directories exist and are visible via these paths?

Do you know that the "D:\folder\file.ext" file exists at the time that this code is called?
0
 

Author Comment

by:jEd
ID: 12192315
> ...can you view "D:\folder\" and "G:\folder\" to verify...

Yes, I can see the folders.

> ...Do you know that the "D:\folder\file.ext" file exists at the time that this code is called?

I believe so, the upload script and the code I posted above are part of the same script, but the copy bit is after the upload bit...
0
 
LVL 14

Expert Comment

by:huji
ID: 12192363
Well I think this line:
objFSO.CopyFile "D:\folder\file.ext", "G:\folder\file.ext"

should be like this:
objFSO.CopyFile "D:\folder\file.ext", "G:\folder\"

Wish I can help
Huji
PS:http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject_copyfile.html
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:huji
ID: 12192385
Description: The second parameter you give to CopyFile method is the destination FOLDER, so if you give "G:\folder\file.ext"
to it, FSO will look for a folder named file.ext, and can not find it. You don't need to give the name of the file in the destination path, just as you do in DOS: copy c:\folder\file.ext g:\folder\

Huji
0
 

Author Comment

by:jEd
ID: 12192448
Sorry huji that didn't work.

I have managed to get the file to copy to another directory on the same server - it seems the problem is with the networked drive...
0
 
LVL 12

Expert Comment

by:GoofyDawg
ID: 12192483
Might be a security issue.... First try trapping the exceptions by placing this at the top of your code:

on error resume next

Then at the bottom type:

if Err > 0 then
   Response.Write Err.Description
end if

to see if any error messages were generated. You can do a Google search on "Err.Description and asp" to get more info. Otherwise, the msdn.microsoft.com site is a great resource for the Err object.

That said, does IUSR_<server1> have sufficient priviledges on the Server 2? You might want to check that out.

GoofyDawg
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 12193775
Drives are mapped for a specific user when they log on.  IIS does not have access to mapped drives.
Run this script and see...
http://devguru.com/Technologies/vbscript/quickref/drivescollection.html

Try using the UNC...
objFSO.CopyFile "D:\folder\file.ext", "\\secondserver\folder\file.ext"
0
 

Author Comment

by:jEd
ID: 12193807
Thanks GoofyDawg, the only error generated was same old 'Path not found' though. I think you might be right about it being a security / privelidges issue.

I am thinking maybe my question should be moved to the 'OS' section seeing as it is not really an ASP issue... ?

I have added IUSR_<server1> to the group on Server2 that has full control over the folder in question, and the network drive is mapped into Server2 using IUSR_<server1>. I can navigate to 'G:\folder\' through windows explorer and save files there manually - but the script won't do it.

Thank you all for your comments so far, please post any new ideas!
0
 

Author Comment

by:jEd
ID: 12193889
joeposter649 - thanks for that, I am out of the office now but back in about 10hrs to let you know!
0
 
LVL 12

Expert Comment

by:GoofyDawg
ID: 12194305
I think joeposter's right. Using a UNC name may just work.

GoofyDawg
0
 

Author Comment

by:jEd
ID: 12197884
Thanks joeposter649, I get a different error - this is progress :-)

  error '8007052e'
  /uploadimages.asp, line 26

Line 26 is

  objFSO.CopyFile "D:\websites\cms\img\example.jpg", "\\server2\websites\cms\img" )

BTW I have 'ASP Upload' running on the server aswell, this gives a more detailed error when trying to save the uploaded file as...

  Persits.Upload.1 error '800a001a'
  Logon failure: unknown user name or bad password.
  /uploadimages.asp, line 13

Line 13 is

  File.SaveAs "\\server2\websites\cms\img\example.jpg")

How do I know which User Server1 is using to connect to Server2 to save the file?
0
 
LVL 14

Expert Comment

by:huji
ID: 12198271
The user on server1 which connects to server2 is IUSR_machine , and it must have permission on the folder it is going to write into.
Second point is, I see paranthesis at the end of your these line of codes:

objFSO.CopyFile "D:\websites\cms\img\example.jpg", "\\server2\websites\cms\img" )
File.SaveAs "\\server2\websites\cms\img\example.jpg")

PLease make sure that they are needed. (Just a simlpe check. I always say "sometimes the solution is so easy that we ignore it thinking about the problem.")
And can you please send the first 13 lines of uploadimages.asp please?
Huji
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 12199594
How did you add iusr_server1 to a group on server2?  
Did you duplicate iusr_server1 on server2???
http://support.microsoft.com/default.aspx?scid=kb;en-us;184566
0
 

Author Comment

by:jEd
ID: 12199854
huji - sorry, the parentheses were just typos, my mistake, they are not in the real code.

joeposter - thanks for the link, I have been through that but still with no success.

There must be some peculiar security set up as I see no reason for everyone's suggestions not to work. We have technical support at the hosting company on the case now, they say:

"Instead of using the IUSR_machine which is used for anonymous requests,
I would suggest I create users for the specific role you require them for."

"Please send me the folder names on the servers where these new users should
be allowed to write to and I will create them straightaway."

I think I have tried this already, but if they get it to work I'll see if I can find out why our methods didn't and let you know...
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 12200642
Error '8007052e' sounds like you used the wrong password to me.
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12201396
Some reference concerning error code 8007052e:
http://www.computerperformance.co.uk/Logon/code/code_8007052E.htm

One question:
You gave permissions on the server2 machine for the IUSR_server1 account.  Did you create a new account on server2 named IUSR_server1, or did you directly use the server1\IUSR_server1 account?
0
 
LVL 5

Accepted Solution

by:
ajitanand earned 600 total points
ID: 12206118
Hi

1. I_User is a low privilege LOCAL account and can not access network resources.
2. Giving Full Control to I_User is not recommnded
3. Even if you give full control to I_USER on one machine it will not work as both machines have different passwords for I_USER as this is controlled by IIS!

Here is how this needs to be done, ideally:

1. Create a Domain User if both servers are on same domain,
OR
Create 1 Local User (say 'fileuser') each on the IIS machine and the Other Server, with SAME! usename and password.

This should be a normal user who can access network resources and full control (with enabled propagation to child objects) on your Mapped Folder


2. Configure your mapped drive to connect through this new User account.

3. In IIS, select the script files that are performing the file write operations -> Properties -> File Security -> Anonymous Access -> Edit -> specify the new user account's username and password -> UNCHECK 'Allow IIS to control Password' -> Click OK OK OK.

---------------------------------

Now give a try. It will work!


rgds,
Ajit Anand
0
 

Author Comment

by:jEd
ID: 12444449
Thanks for all your comments and suggestions, sorry for going quiet for a while!

For anyone still remotely interested the problem has been solved (with the help of the tech support guys at the hosting company).

1. Set up user with write access to the folder in question.
2. In IIS, open the Properties dialog for that folder.
3. Under Directory Security > Authentication and Access Control click Edit.
4. With Enable Anonymous Access checked specify the login details of the user set up in step 1.


File.SaveAs "\\server2\websites\cms\img\example.jpg"

The script now saves to the folder.
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12445484
That sounds like what some of us were getting at, and what ajitanand actually suggested in detail.  Glad to see it's working for ya.  :-)
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12445840
I would point out that the solution at which jEd and his tech-support guys arrived is essentially the same as that already suggested by ajitanand.  Not sure what EE policy is in such cases....
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12446150
As I said above, that would be ajitanand's comment.  Specifically, that dated 10/01/2004 10:22PM PDT.
0
 
LVL 14

Expert Comment

by:huji
ID: 12446575
I agree with Thogek, in that comment http://Q_21151273.html#12206118 is giving the correct answer. I believe it should be accepted as the answer to this question.
Wish I can help
Huji
0
 
LVL 5

Expert Comment

by:ajitanand
ID: 12450531
Glad to know that worked :)
0
 

Author Comment

by:jEd
ID: 12461317
That's fine with me - I couldn't get ajitanand's (10/01/2004 10:22PM PDT) solution to work - but probably down to poor execution rather than the method being incorrect...! The solution I posted was essentially the same so the points go to to ajitanand - nice one!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question