Cannot access remote file from mapped drive

T

tanya.wang

I want to access files from a remote server so I mapped it in my
server under z:\ for \\myserver\web\mysite\images\
I added this UNC path to my IIS virtual directory and name it as
"upload"
but I still cannot use any FSO to read it. Here is my code:

<%
Dim fs
set fs=Server.CreateObject("Scripting.FileSystemObject")

'Method one- NOT exist
if fs.FileExists("\\myserver\web\mysite\images\xxx.gif")=true then
response.write("File exists!")
else
response.write("File NOT exist!")
end if

'Method two - NOT exist as well
if fs.FileExists("Z:\xxx.gif")=true then
response.write("File exists!")
else
response.write("File NOT exist!")
end if



%>

But if i run this html on where my asp is located, it can read this
file -
<img src='../upload/xxx.gif' >

I tried to use server.MapPath("../upload/") but i got this result
D:\Web\sys\upload
While my asp file is located in D:\web\sys
the problem is that there's no physical drive under D:\
I really have no clue here.
All I want to do is to check if a file exists on \\myserver\web\mysite
\images\
If yes then I am going to delete it.. that's why I need to use FSO.

Anyone has ideas?
 
A

Anthony Jones

I want to access files from a remote server so I mapped it in my
server under z:\ for \\myserver\web\mysite\images\
I added this UNC path to my IIS virtual directory and name it as
"upload"
but I still cannot use any FSO to read it. Here is my code:

<%
Dim fs
set fs=Server.CreateObject("Scripting.FileSystemObject")

'Method one- NOT exist
if fs.FileExists("\\myserver\web\mysite\images\xxx.gif")=true then
response.write("File exists!")
else
response.write("File NOT exist!")
end if

'Method two - NOT exist as well
if fs.FileExists("Z:\xxx.gif")=true then
response.write("File exists!")
else
response.write("File NOT exist!")
end if



%>

But if i run this html on where my asp is located, it can read this
file -
<img src='../upload/xxx.gif' >

I tried to use server.MapPath("../upload/") but i got this result
D:\Web\sys\upload
While my asp file is located in D:\web\sys
the problem is that there's no physical drive under D:\
I really have no clue here.
All I want to do is to check if a file exists on \\myserver\web\mysite
\images\
If yes then I am going to delete it.. that's why I need to use FSO.

Anyone has ideas?

The problem is that the file system object knows nothing about IIS or ASP.
Therefore the fact that you have created and virtual directory is
meaningless.

Mapped drives are a user oriented construct. Two different users can could
log on a two different times and each can get their own set of mapped
drives. When no one is logged in there are no mapped drives. Its probably
not as simplistic as that but its not good to rely on mapped drives and you
still need the appropriate priviledges to access the content.

Hence the FSO will attempt to access the share under the IUSR_<machinename>
security token which won't have the appropriate priviledges.

You need the ASP that is using the file system object under a user account
that does have access.

One approach would be to change the anonymous user on the ASP file to a user
that has access.

However you need to be careful that this user only has read access to the
ASP file and read/write to the folder you want to modify. You need to be
sure that a malicuous formation of the URL can't go ahead and delete things
you wouldn't want deleting.
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top