Home All Groups Group Topic Archive Search About

Cannot access remote file from mapped drive



Author
26 Oct 2007 11:25 PM
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?

Author
27 Oct 2007 1:15 PM
Anthony Jones
<tanya.w***@gmail.com> wrote in message
Show quote
news:1193441150.726740.192550@57g2000hsv.googlegroups.com...
> 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.


--
Anthony Jones - MVP ASP/ASP.NET

AddThis Social Bookmark Button