Ftp Spread
This script can be used to publish one file to a multitude of servers in one fell swoop. In order to do so, you need to set up all the servers in the $local array with their correct usernames and passwords. (a feat in itself i know)
Usage: you put this script in the same directory with the file or files that you want to spread to multiple servers and then call it as such: http://localhost/ftpspread.php?file=example.txt&file=exampleimage.jpg&pass=test
With example.txt and examplleimage.jpg being the files you want to spread.
(you can use 1 or more files)
You can change password to you liking *see security disclaimer in code.
*second disclaimer: I curse in my code :)
<?php
//ftpspread.php by miramardesign http://www.miramardesign.com
// this script is designed for advanced users and to be run on localhost only!!
//if you put it on a publicly available webserver you must protect it w/ .htaccess or other simarly high security!!
$file = $_GET[file]; // array of file names retrieved from form/query string
//----------------------edit only between lines ----------------------------------------
// set these to all the servers u want to publish the file to
//$example = array("url" => "example","user" => "anonymous", "pass" => "testpassword", "file" => $file ,"rem_file" => $file, "dir" => "public_html" );
$local = array("url" => "127.0.0.1","user" => "anonymous", "pass" => "test", "file" => $file ,"rem_file" => $file, "dir" => "www" );
$local2 = array("url" => "localhost","user" => "anonymous", "pass" => "test", "file" => $file ,"rem_file" => $file, "dir" => "www" );
$local3 = array("url" => "localhost","user" => "anonymous", "pass" => "test", "file" => $file ,"rem_file" => $file, "dir" => "www" );
$local4 = array("url" => "localhost","user" => "anonymous", "pass" => "test", "file" => $file ,"rem_file" => $file, "dir" => "www" );
$local5 = array("url" => "localhost","user" => "anonymous", "pass" => "test", "file" => $file ,"rem_file" => $file, "dir" => "www" );
$local6 = array("url" => "localhost","user" => "anonymous", "pass" => "test", "file" => $file ,"rem_file" => $file, "dir" => "www" );
$local7 = array("url" => "localhost","user" => "anonymous", "pass" => "test", "file" => $file ,"rem_file" => $file, "dir" => "www" );
$local8 = array("url" => "localhost","user" => "anonymous", "pass" => "test", "file" => $file ,"rem_file" => $file, "dir" => "www" );
// this must contain all the servers above
$host_arr = array($local, $local2, $local3, $local4, $local5, $local6, $local7, $local8,);
//so if you used example above the array would be:
// $host_arr = array($example, $local, $local2, $local3, $local4, $local5, $local6, $local7, $local8,);
$mypass = "test";
//reset this password to your liking and call the page as such ftpspread.php?pass=test
//-----------------------------------------finish editable region------------------------
$pass_get = $_GET[pass];
setcookie('pass', $pass_get);
//save to cookie after first load
$pass_cookie = $_COOKIE[pass];
//basic security password
if ( ($pass_get != $mypass) && ($pass_cookie != $mypass) ) {
header("Location: test.htm");
exit;
}
$mode = $_GET[mode];
$dir = getcwd(); //get current directory
$dir_files = scandir($dir); //scan all files in current directory and put into array for choice in form
$form ="Choose file to spread to all servers:<form action=$_SERVER[PHP_SELF] name=form1 method=get >";
$form .="<input type=hidden name=i value=0 ><br>";
//put scanned files into form by looping through array
for($j = 2; $j < count($dir_files); $j++){
$form .="<input name=file[] type=checkbox value=$dir_files[$j] >$dir_files[$j]<br>";
}
$form .="<input type=submit value=Submit ><br></form>";
//if ( $i > -1 ) //whether to display form
if (isset($_GET[i]))
{
//$i = $_GET[i];
$i += $_GET[i];
$number_of_servers = 3;
$loop = 9 + $_GET[i]; //number of hosts to send to b4 reloading , if u are sending big files the number needs to be smaller
//_____________function that does all the heavy lifting and putting to the servers
function put_multiple($host, $mode, $i){
$ftp = ftp_connect($host[url]);
ftp_login($ftp, $host[user], $host[pass]);
ftp_chdir($ftp, $host[dir]);
$file_arr = $host[file];
for($m = 0; $m < count($file_arr); $m++){
ftp_put($ftp, $i.$file_arr[$m], $file_arr[$m], FTP_BINARY); // i added $i to the filename for testing to create many files in one dir in the test folder
//ftp_put($ftp, $file_arr[$m], $file_arr[$m], FTP_BINARY);
}
return $ftp;
}
while($i < count($host_arr)){ //loop through hosts publishing this biatch
if ($i == $loop){
for($u = 0; $u < count($file); $u++){ //remake query string for redirect
$file_query .="&file[]=".$file[$u];
}
header( "Location: $_SERVER[PHP_SELF]?i=$i&mode=$mode$file_query"); //redirect so the page doesnt timeout
exit;
}
put_multiple($host_arr[$i], $mode, $i); //do it looping through multidimensional arrays
$i++;
} //i am a leeet haxxxor!!!!11!!!
echo "File(s)" ;
print_r($file);
echo " published successfully to $i servers. ";
}else {
//show form if $i isnt set for initial file choice
echo $form;
}
?>
Previous page: Servertime Clock
Next page: Outlook Mail Autosetup

