I need to transfer files between a network of servers all over the world. I have looked into using cURL and ftp_fput() but am having little luck. I can get a transfer going from my local to the server or visa versa but not from server to server.
Basically im trying to replicate Akamai on a very small scale. This is the scenario. I am working from home. I search for a file on Web Server 1 in Oregon. The file doesn't exist. I search my other servers and find that it is located on Server 2 in Germany. I then need to COPY the file from Web Server 2 to Web Server 1. That's it.
I have it all in place except getting the server-to-server transfer to work. Who can help? Thanks much.
6 3390
One other thing. The connections need to be made via FTP. I have IP, USER & PASSWORDS for each account. Thanks.
What exactly are you having a problem with? Do you get any errors? What does happen? What doesn't happen?
Thanks for all your input. Let me explain a little more about what i have done. First of, each of the files I'm transferring are over 1Gb so file_get_contents() wont work. Files are not transferred until requested by the user. I would prefer to do it all in CURL, but as i said im having issues.
I have looked into SST scripts but none seems to satisfy.
My thinking is that cURL cannot directly transfer a file server to server (please correct if wrong). I thought that the way to make it work would be to call a file on Web Server 2 using cURL and add some parameters (file name to transfer) to the call so that when ran it would using cURL transfer the file to Web Server 1. Sound good? Problem, Web Server 2 doesn't have a URL that will resolve to a specific file on the server. Therefor again only cURL via FTP login can be used (as i see it).
So do further define my question, with cURL, is there a way to transfer files between servers directly using a curl statement like -
$ch = curl_init("ftp://theuser:thepass@72.47.251.180/testfile.m4v");
-
but one that works more like below with a location to get and set from/to. I know the following code is incorrect, i just would like to know how to get it right. -
$c = curl_init("ftp://theuser:thepass@72.47.251.180/testfile.m4v","ftp://theuser:thepass@42.76.151.236/testfile.m4v");
-
I know i have left out parts of the cURL process. curl_exec() and curl_close() are pretty standard. Thanks.
SOLVED -
Thanks for everyones help. I am posting my full function for those who may find it useful. To recap, this function "try's" to simulate Akamai's service.
1. GeoLoc user.
2. GeoLoc all servers
3. Calculate distance between user and each server.
4. Sort by distance.
5. Check to see if file is at closest server. If so download.
6. If file not at closest server, copy file from mother server to server missing file. Then notify user via email with download link to closest server. -
function sst() {
-
-
global $_GET, $_SERVER;
-
-
/* start geo loc */
-
// http://www.imaginerc.com/software/GeoCalc/
-
require_once('standards/classes/geoplugin.class.php');
-
$geoplugin = new geoPlugin();
-
// http://www.phpclasses.org/browse/file/25516.html
-
include_once("standards/classes/GeoCalc.class.php");
-
$oGC = new GeoCalc();
-
-
/* set server ip's and FTP logins */
-
$servers = array($_SERVER['REMOTE_ADDR'],'xxx.xx.xx.xxx','xxx.xx.xx.xxx');
-
$user = array('','usr1','usr2');
-
$pass = array('','pass1','pass2',);
-
-
/* get user location */
-
$geo[0]['ip'] = $servers[0];
-
$geoplugin->locate($geo[0]['ip']);
-
$geo[0]['lat'] = $geoplugin->latitude;
-
$geo[0]['lon'] = $geoplugin->longitude;
-
$geo[0]['city'] = $geoplugin->city;
-
$geo[0]['countryName'] = $geoplugin->countryName;
-
-
/* get servers data */
-
for ($i = 1; $i < count($servers); $i++) {
-
-
$geo[$i]['ip'] = $servers[$i];
-
$geo[$i]['user'] = $user[$i];
-
$geo[$i]['pass'] = $pass[$i];
-
$geoplugin->locate($geo[$i]['ip']);
-
$geo[$i]['lat'] = $geoplugin->latitude;
-
$geo[$i]['lon'] = $geoplugin->longitude;
-
$geo[$i]['city'] = $geoplugin->city;
-
$geo[$i]['countryName'] = $geoplugin->countryName;
-
$geo[$i]['dist'] = $oGC->GCDistance($geo[0]['lat'],$geo[0]['lon'],$geo[$i]['lat'],$geo[$i]['lon']);
-
-
}
-
-
/* order by distance. */
-
$geo = orderBy($geo, 'dist');
-
-
/* connect to closeest server */
-
$conn_id = ftp_connect($geo[1]['ip']) or die("Couldn't connect to $ftp_server");
-
ftp_login($conn_id, $geo[1]['user'], $geo[1]['pass']);
-
$contents = ftp_nlist($conn_id, "tts/incoming");
-
ftp_close($conn_id);
-
-
$localfile = '/user/dac15/tts/incoming/';
-
$remotefile = '/user/'.$geo[1]['user'].'/tts/incoming/';
-
-
/* if file is on the closest server. */
-
if (find($_GET['name'],$contents)) {
-
-
// http://www.awesomephp.com/?Tutorials*16/Download-file-with-resume,-stream-and-speed-options.html
-
downloadFile($remotefile,$_GET['name'],900,false);
-
-
}else{
-
-
/* push file to the closest server requesting server.*/
-
$ch = curl_init();
-
$fp = fopen($localfile.$_GET['name'], 'r');
-
curl_setopt($ch, CURLOPT_URL, 'ftp://'.$geo[1]['user'].':'.$geo[1]['pass'].'@'.$geo[1]['ip'].'/'.$remotefile.$_GET['name']);
-
curl_setopt($ch, CURLOPT_UPLOAD, 1);
-
curl_setopt($ch, CURLOPT_INFILE, $fp);
-
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile.$_GET['name']));
-
curl_exec($ch);
-
$error_no = curl_errno($ch);
-
curl_close($ch);
-
if ($error_no == 0) {
-
$error = 'File uploaded succesfully.';
-
-
$mailto[0][0] = $_SERVER['HTTP_EMAIL'];
-
$mailto[0][1] = $_SERVER['HTTP_FNAME'];
-
$mailto[0][2] = $_SERVER['HTTP_LNAME'];
-
-
$content="
-
Dear ".$mailto[0][1]."
-
<br>
-
Your file is ready for download. Go to this link in your preferred web browser.
-
";
-
-
// http://www.xpertmailer.com/
-
if (smtp_mail($mailto,"DoD File Download",$content)) { Return 1; }
-
-
}else{
-
$error = 'File upload error.';
-
echo $error;
-
}
-
-
}
-
-
die;
-
-
}
-
-
function orderBy($data, $field, $reverse_sort='') {
-
$code = "return strnatcmp(\$a['$field'], \$b['$field']);";
-
usort($data, create_function('$a,$b', $code));
-
if ($reverse_sort==1) { krsort($data); }
-
return $data;
-
}
-
I have another question to go along with this post. Once the cURL transfer is started on my 1GB file the screen just sits white while doing its thing (page load bar crawls). Is there a way to finish loading the page while the transfer is in process. This way the user doesn't have to wait for the transfer to finish, they are just there to make it happen. (they are not downloading at the time so it would be okay for them to continue). Thanks.
- /**
-
* Takes a needle and haystack (just like in_array()) and does a wildcard search on it's values.
-
*
-
* @param string $string Needle to find
-
* @param array $array Haystack to look through
-
* @result array Returns the elements that the $string was found in
-
*/
-
function find ($string, $array = array ())
-
{
-
foreach ($array as $key => $value) {
-
unset ($array[$key]);
-
if (strpos($value, $string) !== false) {
-
$array[$key] = $value;
-
}
-
}
-
return $array;
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve Buster |
last post by:
All right, I have read every forum, newsgroup etc about
this issue and no one seems to know how to fix it. I am
getting a "Server Application Unavailable" exception
running my .NET 1.1...
|
by: Andrew |
last post by:
Hello, friends,
I tried to do cross-page posting, i.e., in firstpage.aspx I used
action="secondpage.aspx".
Since I am using asp.net 1.1, so it always goes back to firstpage.aspx
aftern...
|
by: UJ |
last post by:
Folks,
We provide custom content for our customers. Currently we put the files on
our server and people have a program we provide that will download the
files. These files are usually SWF, HTML or...
|
by: bryan |
last post by:
I've got a custom HttpHandler to process all requests for a given
extension. It gets invoked OK, but if I try to do a Server.Transfer I
get an HttpException. A Response.Redirect works, but I really...
|
by: John Salerno |
last post by:
I always read about how you need to set certain file permissions (for
cgi files, for example), but it's never been clear to me *how* you do
this. I know you can run the line
chmod 755...
|
by: Alex |
last post by:
Hello,
I'm trying to write a little php script to transfert some
files from a server to clients (web/http).
It's working fin with small files. But transfering big files
(try on 1Gb) failed!...
|
by: Peter Nofelt |
last post by:
On Server.Transfer(), is there a reason why the previous page's
elements would appear on the new page? Note: this transfer is occuring
between two pages on the same server.
<Scenario>
I'm using...
|
by: Jeff |
last post by:
We have an intranet website that currently uses ActiveX but we need to
make it cross-browser compatible and also get around the problems
we've been having with making it work with IE7 and Vista. We...
|
by: CSINVA |
last post by:
Trying to figure out how to do a cross post page within the code
behind file. I need to do some calculations before I send a string
value to another pages. Here is an example of the concept I...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |