Hello. While working on the project, I encountered a problem that is not solved without the intervention of knowledgeable people.

The question is that through the script I can not get at least a list of directories and files on a network drive in the local network. Globally, the task is this: - you need to take text from one table, and from another table the corresponding application to this text, “stuff” it all into one file and put it in a folder on a remote computer, where the script (also in PHP) should figure out what to what "and on the corresponding tables in the same DB, but already by other machine.
I broke the task into parts, and for a start I decided that it would be more convenient to understand how I could get from the script to a network drive in a local network on a remote computer. I found in the manual a section, "Functions for working with directories" and following my intuition, I tried to get a list of files and folders in a directory (the code from the example).

$d = dir("file://13.73.2.1/d$"); echo "Дескриптор: " . $d->handle . "\n"; echo "Путь: " . $d->path . "\n"; while (false !== ($entry = $d->read())) { echo $entry."\n"; } $d->close(); 

To which I was answered in the browser with something like:

dir () remote file host access not supported

I didn’t deal with it, I decided to try an example from a book that I had on hand, where it was said that the file_get_contents() function also solves similar problems and I tried it in action, only now I indicated the protocol not file:// , but ftp:// . I wrote the following:

 file_get_contents("ftp://13.73.2.1/d$"); 

Why did I write ftp:// here? at that moment, I still did not understand that an FTP server must be configured for such a record.

the answer was approximately

failed to open stream .... operation failed and more was written, permission denied

From what I concluded that my script has no rights to get into the network. I forgot to say that all this happens on the Windows 2008R2 + IIS7 + php7.1 server. Rummaged and found that all sites in IIS are launched under a specially created user IUSR (somehow so called). And that not all of it can be run. In the IIS Manager I Authorization settings, I set my current user (in the "anonymous user authorization") and just in case in the Application Pool, for my Classic.NET AppPool v.4 pool in the advanced settings, I also started it on behalf of the user. Further checked from what user, now comes the request. get_current_user();

Having received a positive result, I thought that now everything will work ... but alas, it did not work. Next, I tried directly in the browser to register the address of the network drive, assuming that I generally do not get access from this environment. Wrote as follows: \\dnsname\d$ . In the browser, I showed everything as it should, while substituting the file:// protocol at the beginning of the recording. But for some reason, the same trick from the script does not work. What else did you try:

  • put three (four) slashes before the address of a network folder somewhere on the network saw that it was written that way, although I did not understand why
  • tried to access from the command line dir \13.73.2.1\d$ - the result was positive.

At the moment, it was not possible to advance further than these experiments, therefore I am asking for help here.

  • one
    Make a symbolic link to this remote folder and work as with a local directory a la mklink /D myFolder "\\shared\folder" - teran
  • @teran Great, thanks for responding. Your comment can be noted as an answer. Thanks again! - AnyYet

1 answer 1

One of the options for accessing the file system of the remote server will be to shift the solution to the OS level, and not to solve it using PCP. As in Linux and windows systems (with ntfs), it is possible to create symbolic (as well as hard) links to directories, incl. and located on a remote server. You can also consider the option to connect a network drive. In general, this task is more about administration, not programming.

using the command

  mklink /D MySymLink "\\server\path\to\folder" 

You can create a symbolic link to a remote directory. You will also need to configure the rights to write to this network resource. If both servers are, for example, in the enterprise network, then this option is quite acceptable. Otherwise, probably, fumble resources is not very good.

PS: to create a link, the command line should be run as administrator.