user123321
user123321

Reputation: 12794

Move File in Server Cluster From ServerA to ServerB

** 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

Answers (4)

1337XyPhR
1337XyPhR

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

SteAp
SteAp

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:

  • A and B try to create an UDP connection to each other
  • Most likely both attempts fail, since no holes are prepared yet
  • But: The NAT devices N1 and N2 create UDP translation states and assign temporary external port numbers
  • A and B contact each others' NAT devices directly on the translated ports; the NAT devices use the previously created translation states and send the packets to A and B

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

datasage
datasage

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

Cfreak
Cfreak

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

Related Questions