*/
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// START CONFIGURATION
//------------------------------------------------------------------------------
// ftp address of destination server
// ex: ftp.mysite.com
$ftp_server = "docelowyserwerftp.pl";
// user name to access ftp destination server
// ex: administrator
$ftp_user = "login.dla.serwera.docelowego";
// password to access ftp destination server
// ex: secret
$ftp_pass = "haslo.dla.ftp.docelowego";
// *ABSOLUTE* (means "starting from the root") FTP path to the directory
// where local file system will be replicated.
// Path must begin with / and must *NOT* end with /
// ex: /html
$ftp_initial_dir = "sciezka do jakiej ma kopiowac";
//------------------------------------------------------------------------------
// END Configuration
//------------------------------------------------------------------------------
//uncomment this if you wish some debugging and comment subsequent line
//error_reporting(E_ALL);
error_reporting(0);
//******************************************************************************
// WARNING : You must not edit anything under this line
// (of course, if you need, you can modify the code)
//******************************************************************************
//------------------------------------------------------------------------------
// Utility functions
//------------------------------------------------------------------------------
// function to forbid recursion through particular dirs
function not_black_list($dir)
{
$black_list = array();
if(in_array($dir, $black_list))
return false;
else
return true;
}
// my ftp_mkdir ......
function lello_mkdir($dir, $ftp_stream)
{
global $ftp_server, $ftp_user, $ftp_pass, $ftp_initial_dir;
//removing trailing backslash
if(strrpos($dir, "/") == strlen($dir) && strlen($dir) > 0)
$dir = substr($dir,0,strrpos($dir, "/")-1);
$tree = explode("/", $ftp_initial_dir.$dir);
for($i=0; $i<count($tree); $i++)
{
if($tree[$i] != "" && $tree[$i] != "/")
{
if($i == 1)
$base = "/";
else
$base = "";
if(ftp_chdir($ftp_stream, $base.$tree[$i]) == false)
{
ftp_mkdir($ftp_stream, $tree[$i]);
ftp_chdir($ftp_stream, $tree[$i]);
}
}
}
}
// ftp connection function
function connetti()
{
global $ftp_server, $ftp_user, $ftp_pass, $ftp_initial_dir;
$conn_id = ftp_connect("$ftp_server");
$login_result = ftp_login($conn_id, "$ftp_user", "$ftp_pass");
if ((!$conn_id) || (!$login_result))
die("Ftp connection error!<br> server name: $ftp_server <br> user name: $ftp_user <br> password: $ftp_pass ");
else
{
lello_mkdir("", $conn_id);
return $conn_id;
}
}
// my ftp_fput
function lello_put($file, $conn_id, $fp, $dir)
{
//as you can see i don't like using reg expr ;-) ... add estensions if needed
$img_type = array ("jpg","JPG","gif","GIF","png","PNG","jpeg","JPEG","swf","SWF","mov","MOV","mp3","MP3","mid","MID");
$ext = explode(".",$file);
if (in_array($ext[1],$img_type))
$ftp_mode = FTP_BINARY;
else
$ftp_mode = FTP_ASCII;
if(strpos($file, "%20") > 0)
$file = str_replace("%20", " ", $file);
if(ftp_fput($conn_id, $file, $fp, $ftp_mode) == false)
echo("Error while transferring file: ".$dir.$file."<br>");
}
// file transferring function
function carica($dir, $file, $conn_id)
{
global $local_base, $ftp_server, $ftp_user, $ftp_pass, $ftp_initial_dir;
$fp = fopen($local_base.$dir."/".$file, "r");
if($fp == false)
echo("cannot open file: ".$local_base.$dir."/".$file."<br>");
lello_mkdir($dir, $conn_id);
lello_put($file, $conn_id, $fp, $dir);
}
//------------------------------------------------------------------------------
// END - Utility functions
//------------------------------------------------------------------------------
//getting local base dir
$local_base = dirname($PATH_TRANSLATED);
if(strrpos($local_base, "/") == strlen($local_base))
$local_base = substr($local_base,0,strrpos($local_base,"/"));
//ftp connection to destination server
$ftp_stream = connetti();
//main recursion throught filesystem
function RecurseDir($directory)
{
global $ftp_stream, $local_base;
if ($dir = opendir($local_base.$directory))
{
$i = 0;
while ($file = readdir($dir))
{
if (($file != ".")&&($file != ".."))
{
$tempDir = $directory."/".$file;
if (is_dir($local_base."/".$tempDir))
{
if(not_black_list($file))
RecurseDir($tempDir);
}
else
{
//file transfer
carica($directory, $file, $ftp_stream);
}
$i++;
}
}//end while
if ($i == 0)
{
// empty directory
}
}
else
{
// directory could not be accessed
echo "cannot open dir ".$local_base.$directory."<br>";
}
}
?>
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Hauling system</title>
</head>
<body>
<b>Activity Report</b><br>
<?php
//main call
RecurseDir();
//closing ftp connection
ftp_quit($ftp_stream);
?>
<br><br><b> ! DONE ! </b>
</body>
</html>
</body>
</html>