<?php
//Move or Upload Folder Using PHP FTP Functions
function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
echo"$_user_name <br/>";
echo"$_user_pass <br/>";
echo" directories are : <br/>";
echo"$local_dir<br/>";
echo"$remote_dir <br/>";
$file = $remote_dir;
// set up basic connection
$_conn_id = ftp_connect($_server);
// login with username and password
$_login_result = ftp_login($_conn_id, $_user_name, $_user_pass);
// check connection
if ((!$_conn_id) || (!$_login_result)) {
$_error = "FTP connection has failed!";
$_error .= "Attempted to connect to $_server for user $_user_name";
$result = false;
} else {
$_error = "Connected to $_server, for user $_user_name";
}
$conn_id = $_conn_id;
@ftp_mkdir($conn_id, $remote_dir);
echo "successfully created $remote_dir\n";
$handle = opendir($local_dir);
while (($file = readdir($handle)) !== false) {
if (($file != '.') && ($file != '..')) {
if (is_dir($local_dir . $file)) {
//recursive call
moveFolder($conn_id, $local_dir . $file . '/', $remote_dir . $file . '/');
echo "successfully uploaded $file\n";
} else
$f[] = $file;
}
}
closedir($handle);
if (count($f)) {
sort($f);
@ftp_chdir($conn_id, $remote_dir);
foreach ($f as $files) {
$from = @fopen("$local_dir$files", 'r+');
$moveFolder = ftp_fput($conn_id, $files, $from, FTP_ASCII);
// @ftp_fput($conn_id, $files, $from, FTP_BINARY);
// check upload status
if (!$moveFolder) {
$this->_error = "FTP upload has failed! From:" . $local_dir . " To: " . $remote_dir;
$result = false;
} else {
$this->_error = "Uploaded $local_dir to $remote_dir as $this->_server";
$result = true;
}
}
}
return $result;
}
?>