Skip to content

Instantly share code, notes, and snippets.

@imitronov
Created October 19, 2017 17:28
Show Gist options
  • Save imitronov/d6d9196fcee9c17af12239f8bd7de4f3 to your computer and use it in GitHub Desktop.
Save imitronov/d6d9196fcee9c17af12239f8bd7de4f3 to your computer and use it in GitHub Desktop.
Бэкап через FTP. Занимает очень много времени. Написан ради примера.
<?php
set_time_limit(0);
ignore_user_abort(true);
header("Connection: close");
ob_flush();
flush();
$ftp_server = '';
$ftp_user_name = '';
$ftp_user_pass = '';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
function backuping($conn_id, $path, $local_path) {
if( !is_dir( $local_path ) ) {
mkdir( $local_path ) or die( 'Не удалось создать папку ' . $local_path );
}
$list = ftp_rawlist($conn_id, $path);
$ptn = '#([d-]{1})([rwxd-]+)([ ]+)([0-9]+)( +)([A-Za-z0-9-_]+)([ ]+)([a-zA-Z0-9]+)([ ]+)([0-9]+)([ ]+)([A-Za-z]+)([ ]+)([0-9]+)([ ]+)([0-9]+):([0-9]+)([ ]+)(.*)#';
foreach( $list as $item ) {
if(preg_match($ptn, $item, $match)) {
if( $match[1] == '-' ) {
$file = $match[19];
ftp_get( $conn_id, $local_path . '/' . $file, $path . '/' . $file, FTP_BINARY );
} elseif ( $match[1] == 'd' AND $match[19] != '.' AND $match[19] != '..' ) {
backuping( $conn_id, $path . '/' . $match[19], $local_path . '/' . $match[19] );
}
}
}
return $files;
}
$files = backuping($conn_id, 'httpdocs', 'httpdocs');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment