Reputation: 12794
** Preface: I don't know much about networking. If i described the set up wrong, I'll try again. **
I have a server cluster of serverA, serverB, and serverC all behind a firewall and on a switch. I want to move a file from serverA to serverB programmatically. In the past when I had to move a file on serverA to another location on serverA I just call exec("sudo mv file1 /home/user/file1"); Can I still do this when multiple servers are involved?
EDIT: All great responses guys. I look into how the server's is cluster and find out if it's a mount or what's going on. Thank you EVERYONE! You guys are my hero!
Upvotes: 1
Views: 340
Reputation: 81
you can use the linux command line tool SCP to copy files over a network via SSH
make sure SSH certificates are configured on the servers.
Example:
exec("sudo cp [-Cr] [[user@]ServerA:]/path/to/file [more...] [[user@]SERVERB:]/path/to/file
Upvotes: 1
Reputation: 11999
While this option is probably a bit too complicated to set up, let me point to UDP hole Punching.
If the addresses of all servers are know and fixed, it is able to traverse firewalls and NATed networks.
In principle, portpunching works like this:
Let A and B be the two hosts, each in its own private network; N1 and N2 are the two NAT devices:
This even works, the addresses of A and B are unknown to each other. In this case, one needs a public known intermediate system S. See the Wikipedia article to learn more.
Upvotes: 1
Reputation: 19573
If you use a common share like nfs that is mounted to all the servers, you can use mv on a file.
If you don't have that option, you can transfer the file to another server using scp or rsync.
Upvotes: 1
Reputation: 19319
Well first of all you should use the native functions to move files around. See rename
: https://www.php.net/rename. It would just mean that you need to make sure the permissions are correct in both locations (likely they need to be owned by the apache
user)
But in answer to your actual question it really depends on the setup. Generally another server you could move files to would have a mount point and it would look like any other directory so you wouldn't need any changes to your code at all. This is probably the best way to do it.
If you have to use FTP or something like that you'll need to use the appropriate libraries for whatever protocol required.
Upvotes: 1