Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

oFileSystemObject.CopyFile ... permission denied?

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
keystrokes
Asked:
keystrokes
  • 6
  • 6
1 Solution
 
markhoyCommented:
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
 
mgfranzCommented:
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
 
keystrokesAuthor Commented:
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.

 
mgfranzCommented:
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
 
keystrokesAuthor Commented:
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
 
mgfranzCommented:
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
 
keystrokesAuthor Commented:
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
 
mgfranzCommented:
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
 
keystrokesAuthor Commented:
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
 
mgfranzCommented:
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
 
keystrokesAuthor Commented:
But this line:

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

does not provide a destination file either.
0
 
mgfranzCommented:
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
 
keystrokesAuthor Commented:
The answer is close enough.
0

Featured Post

Independent Software Vendors: 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!

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now