Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Synchronizing files with remote server

Status
Not open for further replies.

danomac

IS-IT--Management
Aug 2, 2002
731
AM
I have come across an interesting problem of synchronizing files against a remote server (in this case, it's event-driven, so a file would have to be placed on the remote server as well as the local server.)

I have full control over the local server, but limited control over the remote server. No shells allowed, but there is php/apache and ftp.

I thought of 3 possibilities:

1. Sync manually. Of course, this really isn't a possibility as I'm not always the person who generates the event that would require a sync/upload to the remote server.

2. Use the FTP functionality of PHP to copy the file to the remote server. The problem is, if 2 people do this at once, one will be denied - the server allows only 1 FTP login at a time.

3. Set up a script that takes POST input, and restrict it with htaccess so my local server is the only one that access it. This seems the most likely way to do this, except I have not been able to locate something that explains how to get a PHP script to post directly to a form.

Any thoughts?
 
some thoughts on each of your ideas in turn

1. use a cron job?

2. use a batch file to run under a cron job.

3. you can interact with a web server through telnet.

none of these seem great. why do you need to synchronise file systems?
 
It boils down to budget. We can't get more bandwidth for our local server, where the remote has 10-20x the local has.

I thought about a cronjob, but basically after user interaction, the file need to be sync'ed immediately.
 
I would imagine #3 of mine is doable, as I can use the scripts to check where the request is originating from, so I can set it to only allow my local server to call that script.

All I need to do is figure out how to make the script on the local server submit directly to the form on the remote, and it should be OK.
 
are either servers windows based? and can you access one from the other using SMB (or equivalent)
 
The local is linux-based, and the remote is locked down, and won't allow for connections like that.

Good thought though. :)

As an alternative, I guess I could make the remote fetch from the local server, as the local server is on the public internet as well.
 
i'm sure there are linux equivalents of synctoy and syncweb (the latter works over ftp)

dreamweaver also has a remote sync ability. It may be that some similar editors have similar features.

if not, you can write your own script. i'd start with installing a script on each side that will scan the filesystem and return a flatfile of each file, its size and the timestamp it was last "touched". keep a log of all of these so you can check for when the file has been edited on both machines. you might want to consider writing the upload/download scripts as separate scriptlets that can be called by parallel processes. then use proc_open or similar to fork the scripts off as separate threads. Whilst you are still bandwidth limited, you would at least not be limited to serial processes.

you can mimic a posted form pretty easily by opening a socket to port 80 on the remote machine and just shoving some text up the pipe. There are almost certainly some well written classes in the PEAR repository that may do what you need.
 
Thanks, I think I'm going to poke around in PEAR and check out the stream functions in PHP. I should be able to make something to send the files around this way at least.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top