[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Accessing dir on another server - php

Posted on 2010-03-31
19
Medium Priority
?
144 Views
Last Modified: 2014-06-11

Hi all,
         Bascially I am trying to access a directory accroess the servers using php, somthing like (see code section )
But the problem is that it doesn't work, now if I trying doing the same thing being the server 'vmserver', it works fine. But if I trying to access it from another server, it doesnt work and gives me no error megs.
I have access to the server and if I try to access to from run.. then I can do that
I amm using IIS so may be I have to bind the authentications with IUSR account but thats a local account (as u may know, it has to be) so I cant do that#
Does any know how to get over this one?
Really very urgent for me as I have to migrate the web site


Thanks alot.

root = '\\\\vmserver\\C$\\Inetpub\\wwwroot\\reports'; 
$files = array(); 
$folderarray = array(); 
$count = 0; 
$hide = array(                  '_', 
                                '$'             ); 
$discard = false; 
 
if(is_dir($root)) 
{               if( $dh = opendir($root)) 
...

Open in new window

0
Comment
Question by:SameerMirza
  • 9
  • 6
  • 2
17 Comments
 

Author Comment

by:SameerMirza
ID: 29233442
any idea about this one guys?
0
 
LVL 36

Expert Comment

by:gr8gonzo
ID: 29281738
How about mapping the network drive to a drive letter using the correct credentials and then looking at the drive letter with PHP?
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 29300067
And that is most likely your issue - the user running PHP.  Since you are on Windows, this is probably an IUSR account or Network Service.  To complicate things further, Windows assigns those passwords, and I am certainly not the one to recommend you change that.  The IUSR account is only going to exist on the one system, with no counterpart on the remote.  Network Service will exist on the remote, but it is extremely unlikely that their passwords are the same.  

I resolved this problem by running the service from a custom account I created.  My scenario was with SQL Server, which is probably a little easier to deal with than IIS from a user/permissions context.  The user I created was a local user on both systems, with the same password.  On the target system, I created a share specifically for that user with no other access (NTFS or share).  I then changed the service to log on as this account.  It worked great after that.

You could try to map the drive using PHP's exec() command, but I do not recommend it.  The command would be "net use <drive>: \\server\unc\path <password> /user:<username>".  To remove it, "net use <drive>: /delete".  Remember that these credentials must match a local user on the remote server.
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 

Author Comment

by:SameerMirza
ID: 29322282
what is this net use command, I cant find it.  I belive I will have to use an ad account credentials which has access to both the servers, such as my credentials or any other account (obviously if it works then will change it a generic account etc ..)
0
 

Author Comment

by:SameerMirza
ID: 29322397
ok sory, its a windows command :)
0
 

Author Comment

by:SameerMirza
ID: 29326627
that doesnt work, I have created a share from command line and then tried accessing it from the php and it doesnt see the directory.

So even if I give in a password and create share using exec() command, it would work. Because the share (drive mapping) is specific to the account so I belive Case1, which is creating a custom account and run IIS service using that, bind it with both the servers.

but the problem is that Microsoft discurage that. I remember trying this last time when I wasnt able to run dnscmd command and it didnt work. Could you please provide me with the link/set of instructions that you actually followed for doing - from my understanding it is an AD service accocunt that you are using to run the IIS.
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 29333363
>>> Because the share (drive mapping) is specific to the account

I'm pretty sure that is the case.  

My scenario involved SQL Server, not IIS, and I completed it only with local accounts.  It may be discouraged, but it worked.  Local account username on server 1, local account username on server 2, both with the same password.

If you have the ability to use AD accounts, then by all means do so - that is what they are for.  My particular situation did not have that possibility.
0
 

Author Comment

by:SameerMirza
ID: 29334671
ok now what I have trid is,
running web site under my own acocunt, which works fine.
I am admin on both servers have access to the drive I have mapped
But still if I run the code from and look for drive C: I and see but not Y: (which is the mapped drive), I have mapped it from command line
I dont know whats going wrong now. I can see the drive, its under my profile, I am runnign the web site with same acocunt then what could be the problem?

Can any please help me out with it?
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 29336058
IIS does not log on interactively - it logs on as a service.  IIRC, only interactive users get to map a drive, and it exists in the session in which it was created.  On the target server, create a share, give your user the proper NTFS and share rights, and use \\server\sharename from PHP.
0
 

Author Comment

by:SameerMirza
ID: 29337407
ok.
I have created a share on the targer server, for now have set the full control under the same account I am running the web site on the base server.
Calling the share, still doesnt see :/
0
 

Author Comment

by:SameerMirza
ID: 29337691
Please dont give up on this, I realy need to it working

Thanks
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 29417243
If you log in as the web site user, can you access the share by UNC?
0
 
LVL 36

Assisted Solution

by:gr8gonzo
gr8gonzo earned 1000 total points
ID: 29456324
Also check the very last post on this thread:
http://www.webmasterworld.com/forum88/3375.htm
0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 1000 total points
ID: 29523959
That is what I was trying to avoid, actually.  :)  My first comments were directing the OP to use a new, custom local account to supplant the normal IUSR/Network Service account used for this type of thing.  I always prefer not to alter the automated account when possible.

If you wanted to get the password to that account (to set up an identical account on the remote server), that is possible with the adsutil.vbs script, usually found in c:\inetpub\adminscripts.  You will have to edit the script to allow for displaying the password, though.
0
 

Author Comment

by:SameerMirza
ID: 31740598
thx
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 31823705
Is your problem resolved?
0
 

Author Comment

by:SameerMirza
ID: 32676343
yes, I will soon post the solution
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

590 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