?
Solved

oFileSystemObject.CopyFile ... permission denied?

Posted on 2003-02-25
13
Medium Priority
?
380 Views
Last Modified: 2007-12-19
When I do a copy file with the filesystemobject, it gave me this error, but when I read or create a file in the same directory, it works.  Anyone has any ideas?

I certainly will increase the points accordingly if it's question is answered correctly.  
0
Comment
Question by:keystrokes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
13 Comments
 
LVL 7

Expert Comment

by:markhoy
ID: 8018039
The user IUSR_machine name needs RWX permissions for that folder (set using IIS) so that it can read, write and delete files in that folder.

see www.aspfaqs.com > FSO for more detailed info on permissions and techniques.
0
 
LVL 18

Accepted Solution

by:
mgfranz earned 80 total points
ID: 8018100
What if the Write folder is not under IIS control?  ;-)

But yes, you need to set write permissions to the authenticated user or IUSER_ on the folder you are Reading and Writing to.  Note the part of having Read permission to IUSER_ on the folder you are reading from...
0
 
LVL 3

Author Comment

by:keystrokes
ID: 8018189
If it's a RWX security problem, wouldn't it restrict me from creating or reading a file as well?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 18

Expert Comment

by:mgfranz
ID: 8018232
Not if the folder you are writing to already has IUSER_ permissions, it's the folder you are trying to COPY FROM that needs to have IUSER_ Read/Write permissions.
0
 
LVL 3

Author Comment

by:keystrokes
ID: 8018351
I sent myself out in a wild goose chase.  It turn out that the file destination also needs to include the file name which is not the case in MSDN(!).  So the error message "permission denied" is misleading.  Thanks for all your support.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 8018412
I don't agree;

object.CopyFile ( source, destination[, overwrite] )

overwrite
Optional. Boolean value that indicates if existing files are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. Note that CopyFile will fail if destination has the read-only attribute set, regardless of the value of overwrite.

FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"

If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching files. Otherwise, destination is assumed to be the name of a file to create. In either case, three things can happen when an individual file is copied.

If destination does not exist, source gets copied. This is the usual case. If destination is an existing file, an error occurs if overwrite is false. Otherwise, an attempt is made to copy source over the existing file. If destination is a directory, an error occurs. An error also occurs if a source using wildcard characters doesn't match any files. The CopyFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes made before an error occurs.

Me thinks your script may be to blame... ;-)
Here is the lowdown on Copy File; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsmthcopy.asp

0
 
LVL 3

Author Comment

by:keystrokes
ID: 8019134
mqfranz:

My script is embarrassedly simple.  Please feel free to evaluate.  Also, if you can show me how to fix this script to make it work according to your senario, I'll give you 100 points.

Dim oFS, sFileSpec, sFileName
Set oFS = Server.CreateObject("Scripting.FileSystemObject")

'this line gave me the permission error:
oFS.CopyFile "c:\test.txt","c:\"

'this line make copy a file called "test2.txt" in the directory:
oFS.CopyFile "c:\test.txt","c:\test2.txt"

Set oFS=Nothing

Please note: I also tried to copy it to a different directory, like "c:\mytempdir\".  I am running this on my local machine and I am the admin.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 8020228
There is nothing wrong with your script if that's all there is to it, this works on my machine;

oFS.CopyFile ("c:\temp1\test.txt","c:\temp2\test2.txt", true)

Again, I have set IUSER_ permissions on both temp1 and temp2 to Read/Write.  The file exists in temp1 not temp2.

Make sure the mytempdir has the proper permissions, it may also have to be set-up as a virtual dir in IIS.
0
 
LVL 3

Author Comment

by:keystrokes
ID: 8020749
mqfranz:

I meant for you to make this line work:

oFS.CopyFile "c:\test.txt","c:\"

because you wrote this:

[I don't agree;

object.CopyFile ( source, destination[, overwrite] )

overwrite
Optional. Boolean value that indicates if existing files are to be overwritten. If true, files are overwritten; if false, they are not. The default is true. Note that CopyFile will fail if destination has the read-only attribute set, regardless of the value of overwrite.

FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"]

and the destination does not include the destination file name is all what I was talking about in the previous comment which you replied to.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 8021445
This will never work;

oFS.CopyFile "c:\test.txt","c:\"

Notice there is no target file.  This will work;

oFS.CopyFile "c:\test.txt","c:\test2.txt", true

Providing the IUSER_ has Read/Write perms.
0
 
LVL 3

Author Comment

by:keystrokes
ID: 8025807
But this line:

FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"

does not provide a destination file either.
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 8026380
Sorry, bad syntax str, I should have left off the trailing /.

From MSDN;

Wildcard characters can only be used in the last path component of the source argument. For example, you can use:

[VBScript]
FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"

But you cannot use:

[VBScript]
FileSystemObject.CopyFile "c:\mydocuments\*\R1???97.xls", "c:\tempfolder"

If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching files. Otherwise, destination is assumed to be the name of a file to create. In either case, three things can happen when an individual file is copied.

If destination does not exist, source gets copied. This is the usual case.  If destination is an existing file, an error occurs if overwrite is false. Otherwise, an attempt is made to copy source over the existing file. If destination is a directory, an error occurs.  An error also occurs if a source using wildcard characters doesn't match any files. The CopyFile method stops on the first error it encounters. No attempt is made to roll back or undo any changes made before an error occurs.
0
 
LVL 3

Author Comment

by:keystrokes
ID: 8036740
The answer is close enough.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

764 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