| 1 |
<?php |
| 2 |
|
| 3 |
// Direct calls to this file are Forbidden when core files are not present |
| 4 |
// Thanks to Ed from ait-pro.com for this code |
| 5 |
// @since 2.1 |
| 6 |
// doesn't work when file is included by script :-( |
| 7 |
/* |
| 8 |
if ( !function_exists('add_action') ){ |
| 9 |
header('Status: 403 Forbidden'); |
| 10 |
header('HTTP/1.1 403 Forbidden'); |
| 11 |
exit(); |
| 12 |
} |
| 13 |
|
| 14 |
if ( !current_user_can('manage_options') ){ |
| 15 |
header('Status: 403 Forbidden'); |
| 16 |
header('HTTP/1.1 403 Forbidden'); |
| 17 |
exit(); |
| 18 |
} |
| 19 |
*/ |
| 20 |
// |
| 21 |
// |
| 22 |
echo "<h2>Send package to FTP site</h2>"; |
| 23 |
|
| 24 |
// set up variables |
| 25 |
$host = get_option('backupbreeze_ftp_host'); |
| 26 |
$user = get_option('backupbreeze_ftp_user'); |
| 27 |
$pass = get_option('backupbreeze_ftp_pass'); |
| 28 |
$subdir = get_option('backupbreeze_ftp_subdir'); |
| 29 |
$wp_upload_dir = wp_upload_dir(); |
| 30 |
|
| 31 |
$wp_upload_dir['basedir'] = str_replace('\\', '/', $wp_upload_dir['basedir']); |
| 32 |
$remotefile = $subdir.'/'.$filename; |
| 33 |
$localfile = trailingslashit($wp_upload_dir['basedir'].'/db-backup'). $filename; |
| 34 |
|
| 35 |
// see if port option is blank and set it to 21 if it isn't |
| 36 |
if (!get_option('backupbreeze_ftp_port')) { |
| 37 |
$port == '21'; |
| 38 |
} else { |
| 39 |
$port = get_option('backupbreeze_ftp_port'); |
| 40 |
} |
| 41 |
// extra security |
| 42 |
// @since 2.1 |
| 43 |
// doesn't work when file is included by script :-( |
| 44 |
// If in WP Dashboard or Admin Panels |
| 45 |
// if ( is_admin() ) { |
| 46 |
// If user has WP manage options permissions |
| 47 |
// if ( current_user_can('manage_options')) { |
| 48 |
// connect to host ONLY if the 2 security conditions are valid / met |
| 49 |
$conn = ftp_connect($host,$port); |
| 50 |
// } |
| 51 |
// } |
| 52 |
|
| 53 |
// @since 1.6 |
| 54 |
// new passive FTP connection to avoid timeouts |
| 55 |
// thanks to Kara for this code ;-) |
| 56 |
|
| 57 |
if (!$conn) { |
| 58 |
echo '<div class="error">Could not connect to ftp server. This will be local backup.<br /></div>'; |
| 59 |
} |
| 60 |
else { |
| 61 |
echo "Connected to $host.<br />"; |
| 62 |
// log in to host |
| 63 |
$result = @ftp_login($conn, $user, $pass); |
| 64 |
if (!$result) { |
| 65 |
echo '<div class="error">Could not log on as $user. This will be local backup.<br /></div>'; |
| 66 |
} |
| 67 |
else { |
| 68 |
echo '<div class="error">Logged in as $user<br /></div>'; |
| 69 |
// Switch to passive mode |
| 70 |
ftp_pasv($conn, true); |
| 71 |
// upload file |
| 72 |
echo '<div class="error">Uploading package to FTP repository...<br /></div>'; |
| 73 |
if (!$success = ftp_put($conn, $remotefile, $localfile, FTP_BINARY)) { |
| 74 |
echo '<div class="error">Error: Could not upload file. This will be local backup.<br /></div>'; |
| 75 |
} |
| 76 |
else { |
| 77 |
echo '<div class="error">File was uploaded successfully <br /></div>'; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
// close connection to host |
| 82 |
ftp_quit($conn); |
| 83 |
|
| 84 |
// echo "... Done!"; |
| 85 |
|
| 86 |
?> |