How can I send a file from one server to another?

For example, on the local server (Denver), the site engine creates a synchronization file (mainly SQL queries) in the form of XML. On an external server, there is a script that receives this file and executes commands from the file. All actions must take place on the local server.

  • Should an external server return a result? If so, to whom? Who needs a result - that works. Since the intermediate server is local, I suspect that you are the master there, and there will be no problems with privileges. - alexlz

2 answers 2

The simplest example is:

<?php $url = 'http://somedomain/filepost.php'; // url для загрузки $file = 'c:\\fail_dlja_uploda.txt'; // выгружаемый файл $fh = fopen($file, 'r'); if ($curl = curl_init()) { curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_INFILE, $fh); curl_setopt($curl, CURLOPT_INFILESIZE, filesize($file)); curl_setopt($curl, CURLOPT_UPLOAD, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); $out = curl_exec($curl); echo $out; curl_close($curl); } fclose($fh); ?> 

You may have a line:

 curl_setopt($curl, CURLOPT_UPLOAD, true); 

replaced by:

 curl_setopt($curl, CURLOPT_POST, true); 

or even remove them.

    This is quite feasible ajax'ом . only it will be necessary to transfer variables, then on an external server it will not be necessary to work with the file, to parse it. If you simply transfer variables, it will be faster. and feasible.