PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 6.11
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v6.11
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / includes / admin / Destination / FTP / test-ftp.php

test-ftp.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 6.11, at includes/admin/Destination/FTP/test-ftp.php

70 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Destination test.
4 *
5 * @package wpdbbkp
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 if ( ! function_exists( 'add_action' ) ) {
13 header( 'Status: 403 Forbidden' );
14 header( 'HTTP/1.1 403 Forbidden' );
15 exit();
16 }
17
18 if ( ! current_user_can( 'manage_options' ) ) {
19 header( 'Status: 403 Forbidden' );
20 header( 'HTTP/1.1 403 Forbidden' );
21 exit();
22 }
23
24 /**
25 * Test app.
26 */
27 function backupbreeze_test_ftp() {
28
29 // Now let's see if we can connect to the FTP repo.
30 $host = get_option( 'backupbreeze_ftp_host' );
31 $user = get_option( 'backupbreeze_ftp_user' );
32 $pass = get_option( 'backupbreeze_ftp_pass' );
33 $subdir = get_option( 'backupbreeze_ftp_subdir' );
34 if ( '' === $subdir ) {
35 $subdir = '/';
36 }
37
38 if ( is_admin() ) {
39 // If user has WP manage options permissions.
40 if ( current_user_can( 'manage_options' ) ) {
41 // Connect to host ONLY if the 2 security conditions are valid / met.
42 $conn = ftp_connect( $host );
43 }
44 }
45
46 if ( ! $conn ) {
47 $trouble = 'I could not connect to your FTP server.<br />Please check your FTP Host and try again.';
48 return $trouble;
49 }
50
51 $result = ftp_login( $conn, $user, $pass );
52 if ( ! $result ) {
53 $trouble = 'I could connect to the FTP server but I could not log in.<br />Please check your credentials and try again.';
54 return $trouble;
55 }
56
57 $success = ftp_chdir( $conn, $subdir );
58 if ( ! $success ) {
59 $trouble = 'I can connect to the FTP server, but I cannot change into the FTP subdirectory you specified. <br />Is the path correct? Does the directory exist? Is it wrritable?<br />Please check using an FTP client like FileZilla.';
60 return $trouble;
61 }
62
63 $trouble = 'OK';
64
65 // Lose this connection.
66 ftp_close( $conn );
67 return $trouble;
68
69 }
70