Mike Mike -4 years ago 101
PHP Question

bat script executed on server B cannot connect to server A to copy files

I have a website that uses two servers to run(A and B). It displays reports pulled from MSSQL. The servers are both Windows 2012 R2. I have a .bat file that I created to copy the websites files from one server(B) to the other(A) so that I can keep them updated together. I only manually update the files for the website on server B.

I can run the .bat file fine on my computer or directly on either server and it works fine all the files get copied over from B to A. Here's the .bat file:

rem echo off

SET source="D:\WebContent\engsys.corp.ftr.com"
SET source2="\\MAFINFWWWPV02\D$\WebContent\engsys.corp.ftr.com"
SET dest1="\\MAFINFWWWPV01\engsys.corp.ftr.com"

xcopy %source% %dest1% /E /Y

rem xcopy %source2% %dest1% /E /Y

echo #%username%@%computername%

I am using variables so that I can switch them quickly for testing.

I created a button on one of my web pages so that I could just click the button and it'll run the .bat file. However, it doesn't copy the files when I run it using the button. In the website when I click the button this is called:
system('cmd /c ' . $script);
Then on the web page it displays

Invalid drive specification 0 File(s) copied

If I change the destination to
then it runs fine and copies the files to the folder on the server that is running the script. If I change it to
then I get the same error as if I was running the original.
is the mapped drive for the other server(A) that I put on B.

I know that the servers can talk to each other as I've mapped drives from one server to the other for the place where the website files are stored so that each server has a mapped drive to the other servers website files(
). I had thought that I could use this as the destination. That just gives the same error of not a valid drive though.

Since I'm not the only admin that will be using the website I really need this button to work. There are 2 of us that might update the files, but we have a team that might need to us the Admin page to update certain things and then would need to use the button to ensure that they get copied to both servers.


I commented out the
echo off
here's the results of running the .bat file. I did format it so that it's not just one long string.

>rem echo off
>SET source="D:\WebContent\engsys.corp.ftr.com"
>SET source2="\\MAFINFWWWPV02\D$\WebContent\engsys.corp.ftr.com"
>SET dest1="\\MAFINFWWWPV01\engsys.corp.ftr.com"
>xcopy "D:\WebContent\engsys.corp.ftr.com" "\\MAFINFWWWPV01\engsys.corp.ftr.com" /E /Y Invalid drive specification 0 File(s) copied
>rem xcopy "\\MAFINFWWWPV02\D$\WebContent\engsys.corp.ftr.com" "\\MAFINFWWWPV01\engsys.corp.ftr.com" /E /Y
>rem pause

UserName computer name when run from the server without using the website:


Answer Source

Here is what finally worked:

This is in the php file:

case 'CopyFiles':
$script = chr(92) . chr(92) . 'MAFINFWWWPV02\D$\WebContent\engsys.corp.ftr.com\BatchFiles\CopyFiles.bat';
system('cmd /c ' . $script); echo " <br>";

This is the .bat file:

echo off

SET source2="\\MAFINFWWWPV02\engsys.corp.ftr.com"

START /wait NET USE L: "\\MAFINFWWWPV01\engsys.corp.ftr.com" Password /user:corp\mmm976

xcopy %source2% L: /E /Y /Q


After having the bat file map the shared drive I was able to then use it to copy the files. I don't really know why this worked when I had the location mapped previously and it didn't work, but it is now.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download