3

I need to copy a file from one computer to another computer which is connected to lan network. I have IP address of that two machines. I have used code like this to achieve it ,

$file = 'file.text';// inside htdocs folder
$newfile = '\\\\192.168.1.15\\htdocsfolder\\';
if ( copy($file, $newfile) ) {
    echo "Copy success!";
}else{
    echo "Copy failed.";
}

but copy failed. How to debug, why file is not copied to another computer htdocs folder? whether i need to change share access on both computers?

Please help. Thanks

Oerd
  • 2,256
  • 1
  • 21
  • 35
DarkRose
  • 125
  • 4
  • 12

2 Answers2

0

You seem to be on a windows machine. Here are a couple of things to keep in mind and check for (which are a variation of the same theme):

  1. If this is a scheduled task/batch job, try executing it from the terminal and check any errors you might get (beware of relative paths):

    C:\> path-to-php script.php

  2. Otherwise, if you can, run it as the webserver's user and see below:

    • Webserver process needs to have write access to \\192.168.1.15\htdocsfolder and read access to htdocs folder.
    • Check the user your webserver process runs as. Use your favorite process/task/service manager to check for the exact username and see if this user has the required access modes.
    • If you are in an Active Directory environment give access to the username identified above
    • If OTOH you are in a LAN, make sure the username exists (is a valid user) and has the same password on both machines.
    • If you do this right, permissions for Everyone are not necessary (and usually a bad thing)
    • Not to pick on MS and Windows, but do make sure about shares and permissions from "Manage my computer" -> "System Tools" -> "Shared Folder" as specified by Microsoft

Debugging is hard, you'll have to do a lot of further research on your own, Google and SO are your friends.

Oerd
  • 2,256
  • 1
  • 21
  • 35
0

please check that the user executing php script has the access on remote file system. If scripts are executed on Linux, its useful to mount remote share. Just to add, your code worked fine with my case.

Sunit
  • 403
  • 1
  • 5
  • 6