Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copyfile some times works! 1

Status
Not open for further replies.

Papa Bear

Programmer
Feb 1, 2003
37
GB
Hi All
I am trying to use copy file to upload some files. If I copy from C:\Windows, the copy works. But if I try from a folder called C:\Joda, It doesn't. This is some simple test code I have setup.
Code:
<%
dim SourceFile, DestFile, DBconn, fs, fo

Set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder(Server.MapPath("images"))
response.write fo & "<br>"

if fs.driveexists("c:") = true then
      Response.Write("Drive c: exists.")&"<br>"
Else
      Response.Write("Drive c: does not exist.")&"<br>"
End If

If fs.FolderExists("c:\WINDOWS") = true Then
      Response.Write("Folder c:\windows exists.")&"<br>"
Else
      Response.Write("Folder c:\WINDOWS does not exist.")&"<br>"
End If

If fs.FileExists("C:\WINDOWS\win.ini") = true Then
      Response.Write("File C:\WINDOWS\win.ini exists.")&"<br>"
Else
      Response.Write("File C:\WINDOWS\win.ini does not exist.")&"<br>"
End If

SourceFile = "C:\windows\win.ini" 
DestFile = Fo & "\" 
fs.CopyFile SourceFile, Fo&"\", true 

If fs.FolderExists("c:\Joda") = true Then
      Response.Write("Folder c:\Joda exists.")&"<br>"
Else
      Response.Write("Folder c:\Joda does not exist.")&"<br>"
End If

If fs.FileExists("C:\Joda\test.txt") = true Then
      Response.Write("File C:\Joda\test.txt exists.")&"<br>"
Else
      Response.Write("File C:\Joda\test.txt does not exist.")&"<br>"
End If


SourceFile = "C:\Joda\test.txt" 
DestFile = Fo & "\" 
fs.CopyFile SourceFile, Fo&"\", true 

set fs=nothing

%>
When I run this, I get the following results
Code:
Drive c: exists.
Folder c:\windows exists.
File C:\WINDOWS\win.ini exists.
Folder c:\Joda does not exist.
File C:\Joda\test.txt does not exist.

Microsoft VBScript runtime error '800a004c' 

Path not found 

/Joda/Do_Upload.asp, line 58
Before you ask, I have double, triple, 10 times checked the folder and file do exist. I have also checked on another PC.

Any one any ideas PLEASE.
 
PS. I have also tried with another folder C:\Dell, and this does not work either.

Steve
 
does the user that the site runs as have permissions to those folders?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi Chris
Don't understand your question. This site is still under test and I am the user. I am trying to upload gif files from my C drive to the server so they appear on the web page. This way, when a new file is uploaded, the web page changes. Eventualy, a user will be able to update there own site without me having to FTP files for him. Hope that makes it clearer.

Steve
 
With webservers each site runs in the context of a different username NOT as the person who is logged on to the machine.

And eaxh site that is setup has a different user. Each user only has access permissions granted to the folders that the site documents are located in.


Is the website running on a remote server? Or are you running this on you own machine?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi Chris

A bit of back ground. I originally created this site for a flower wholesaler in HTML. It runs on a hosting site. (Fasthosts). One of the pages was for special offers, which will be updated quite regularly. I made this page ASP which reads an sql database so he could update the text whenever he wanted using an update page which only he (and I) can see as it needs a password. Most people who visit the site cannot even see the login page. He can even specify which gif files will be displayed on each page. This bit works fine. I have been writing database pages in ASP for some time.
I have now decided to let him upload his own images so he doesn’t have to keep contacting me. This is the code above much simplified. (I check for file types etc) The only folder I can get the upload to work from is C:/windows and C:/temp. I have tried lots of other folder and each one cannot be found with copyfile or folderexists or fileexists.

Steve
 
My advice would be to upload the files into a directory within your web site as defined by Server.MapPath rather than hard code a directory. This keeps your files in one place and allows you to port your code to another server more easily.

In you code you have this line : response.write fo & "<br>"

Is this returning anything? If not then try: set fo=fs.GetFolder(Server.MapPath("."))

then append images to fo: PathToImages = fo & "/images"

and use this location to store your images. You will however still need to change the permission [IUSR_MACHINENAME] on this folder to allow the ASP application to read/write to the folder.

BDC.
 
ASP runs on the SERVER it has no access to the client machine no matter what the folders are called.

And if the server is setup with security in mind (that may exclude Fasthost) the server usernames will have NO access at all to C:\windows.

They should be limited in the ACL to ONLY the folders that constitute the web site.

And unless you are connecting to the server via RDP and creating this c:\JODA folder it will not exist on the server

You should ONLY be able to upload files to folders that are withing your website root folder.




Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thanks Chris and BDC

My Mistake. Just found out this morning that I am accesing the C drive ON THE SERVER AAAAHH!

All the examples I have read show the C drive so I just presumed it was my PC it was meaning. Sorry for all the trouble I have caused you.

I will have to have a rethink. Just trying to save myself some work in uploading images every week or so.

Steve

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top