Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../methods
File: ftp.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.');
[2] Fix | Delete
[3] Fix | Delete
// Converted to array options: yes
[4] Fix | Delete
// Converted to job_options: yes
[5] Fix | Delete
[6] Fix | Delete
// Migrate options to new-style storage - May 2014
[7] Fix | Delete
if (!is_array(UpdraftPlus_Options::get_updraft_option('updraft_ftp')) && '' != UpdraftPlus_Options::get_updraft_option('updraft_server_address', '')) {
[8] Fix | Delete
$opts = array(
[9] Fix | Delete
'user' => UpdraftPlus_Options::get_updraft_option('updraft_ftp_login'),
[10] Fix | Delete
'pass' => UpdraftPlus_Options::get_updraft_option('updraft_ftp_pass'),
[11] Fix | Delete
'host' => UpdraftPlus_Options::get_updraft_option('updraft_server_address'),
[12] Fix | Delete
'path' => UpdraftPlus_Options::get_updraft_option('updraft_ftp_remote_path'),
[13] Fix | Delete
'passive' => true
[14] Fix | Delete
);
[15] Fix | Delete
UpdraftPlus_Options::update_updraft_option('updraft_ftp', $opts);
[16] Fix | Delete
UpdraftPlus_Options::delete_updraft_option('updraft_server_address');
[17] Fix | Delete
UpdraftPlus_Options::delete_updraft_option('updraft_ftp_pass');
[18] Fix | Delete
UpdraftPlus_Options::delete_updraft_option('updraft_ftp_remote_path');
[19] Fix | Delete
UpdraftPlus_Options::delete_updraft_option('updraft_ftp_login');
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
if (!class_exists('UpdraftPlus_BackupModule')) require_once(UPDRAFTPLUS_DIR.'/methods/backup-module.php');
[23] Fix | Delete
[24] Fix | Delete
class UpdraftPlus_BackupModule_ftp extends UpdraftPlus_BackupModule {
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Get FTP object with parameters set
[28] Fix | Delete
*
[29] Fix | Delete
* @param String $server Specify Server
[30] Fix | Delete
* @param String $user Specify Username
[31] Fix | Delete
* @param String $pass Specify Password
[32] Fix | Delete
* @param Boolean $disable_ssl Indicate whether to disable SSL
[33] Fix | Delete
* @param Boolean $disable_verify Indicate whether to disable verifiction
[34] Fix | Delete
* @param Boolean $use_server_certs Indicate whether to use server certificates
[35] Fix | Delete
* @param Boolean $passive Indicate whether to use passive FTP mode
[36] Fix | Delete
* @return Array
[37] Fix | Delete
*/
[38] Fix | Delete
private function getFTP($server, $user, $pass, $disable_ssl = false, $disable_verify = true, $use_server_certs = false, $passive = true) {
[39] Fix | Delete
[40] Fix | Delete
if ('' == trim($server) || '' == trim($user) || '' == trim($pass)) return new WP_Error('no_settings', sprintf(__('No %s settings were found', 'updraftplus'), 'FTP'));
[41] Fix | Delete
[42] Fix | Delete
if (!class_exists('UpdraftPlus_ftp_wrapper')) include_once(UPDRAFTPLUS_DIR.'/includes/ftp.class.php');
[43] Fix | Delete
[44] Fix | Delete
$port = 21;
[45] Fix | Delete
if (preg_match('/^(.*):(\d+)$/', $server, $matches)) {
[46] Fix | Delete
$server = $matches[1];
[47] Fix | Delete
$port = $matches[2];
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$ftp = new UpdraftPlus_ftp_wrapper($server, $user, $pass, $port);
[51] Fix | Delete
[52] Fix | Delete
if ($disable_ssl) $ftp->ssl = false;
[53] Fix | Delete
$ftp->use_server_certs = $use_server_certs;
[54] Fix | Delete
$ftp->disable_verify = $disable_verify;
[55] Fix | Delete
$ftp->passive = ($passive) ? true : false;
[56] Fix | Delete
[57] Fix | Delete
return $ftp;
[58] Fix | Delete
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* WordPress options filter, sanitising the FTP options saved from the options page
[63] Fix | Delete
*
[64] Fix | Delete
* @param Array $settings - the options, prior to sanitisation
[65] Fix | Delete
*
[66] Fix | Delete
* @return Array - the sanitised options for saving
[67] Fix | Delete
*/
[68] Fix | Delete
public function options_filter($settings) {
[69] Fix | Delete
if (is_array($settings) && !empty($settings['version']) && !empty($settings['settings'])) {
[70] Fix | Delete
foreach ($settings['settings'] as $instance_id => $instance_settings) {
[71] Fix | Delete
if (!empty($instance_settings['host']) && preg_match('#ftp(es|s)?://(.*)#i', $instance_settings['host'], $matches)) {
[72] Fix | Delete
$settings['settings'][$instance_id]['host'] = rtrim($matches[2], "/ \t\n\r\0x0B");
[73] Fix | Delete
}
[74] Fix | Delete
if (isset($instance_settings['pass'])) {
[75] Fix | Delete
$settings['settings'][$instance_id]['pass'] = trim($instance_settings['pass'], "\n\r\0\x0B");
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
}
[79] Fix | Delete
return $settings;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
public function get_supported_features() {
[83] Fix | Delete
// The 'multi_options' options format is handled via only accessing options via $this->get_options()
[84] Fix | Delete
return array('multi_options', 'config_templates', 'multi_storage', 'conditional_logic');
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
public function get_default_options() {
[88] Fix | Delete
return array(
[89] Fix | Delete
'host' => '',
[90] Fix | Delete
'user' => '',
[91] Fix | Delete
'pass' => '',
[92] Fix | Delete
'path' => '',
[93] Fix | Delete
'passive' => 1
[94] Fix | Delete
);
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
public function backup($backup_array) {
[98] Fix | Delete
[99] Fix | Delete
global $updraftplus;
[100] Fix | Delete
[101] Fix | Delete
$opts = $this->get_options();
[102] Fix | Delete
[103] Fix | Delete
$ftp = $this->getFTP(
[104] Fix | Delete
$opts['host'],
[105] Fix | Delete
$opts['user'],
[106] Fix | Delete
$opts['pass'],
[107] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_nossl'),
[108] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_disableverify'),
[109] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_useservercerts'),
[110] Fix | Delete
$opts['passive']
[111] Fix | Delete
);
[112] Fix | Delete
[113] Fix | Delete
if (is_wp_error($ftp) || !$ftp->connect()) {
[114] Fix | Delete
if (is_wp_error($ftp)) {
[115] Fix | Delete
$updraftplus->log_wp_error($ftp);
[116] Fix | Delete
} else {
[117] Fix | Delete
$this->log("Failure: we did not successfully log in with those credentials.");
[118] Fix | Delete
}
[119] Fix | Delete
$this->log(__("login failure", 'updraftplus'), 'error');
[120] Fix | Delete
return false;
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
// $ftp->make_dir(); we may need to recursively create dirs? TODO
[124] Fix | Delete
[125] Fix | Delete
$updraft_dir = $updraftplus->backups_dir_location().'/';
[126] Fix | Delete
[127] Fix | Delete
$ftp_remote_path = trailingslashit($opts['path']);
[128] Fix | Delete
foreach ($backup_array as $file) {
[129] Fix | Delete
$fullpath = $updraft_dir.$file;
[130] Fix | Delete
$this->log("upload attempt: $file -> ftp://".$opts['user']."@".$opts['host']."/${ftp_remote_path}${file}");
[131] Fix | Delete
$timer_start = microtime(true);
[132] Fix | Delete
$size_k = round(filesize($fullpath)/1024, 1);
[133] Fix | Delete
// Note :Setting $resume to true unnecessarily is not meant to be a problem. Only ever (Feb 2014) seen one weird FTP server where calling SIZE on a non-existent file did create a problem. So, this code just helps that case. (the check for non-empty upload_status[p] is being cautious.
[134] Fix | Delete
$upload_status = $updraftplus->jobdata_get('uploading_substatus');
[135] Fix | Delete
if (0 == $updraftplus->current_resumption || (is_array($upload_status) && !empty($upload_status['p']) && 0 == $upload_status['p'])) {
[136] Fix | Delete
$resume = false;
[137] Fix | Delete
} else {
[138] Fix | Delete
$resume = true;
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
if ($ftp->put($fullpath, $ftp_remote_path.$file, FTP_BINARY, $resume, $updraftplus)) {
[142] Fix | Delete
$this->log("upload attempt successful (".$size_k."KB in ".(round(microtime(true)-$timer_start, 2)).'s)');
[143] Fix | Delete
$updraftplus->uploaded_file($file);
[144] Fix | Delete
} else {
[145] Fix | Delete
$this->log("ERROR: FTP upload failed");
[146] Fix | Delete
$this->log(__("upload failed", 'updraftplus'), 'error');
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
return array('ftp_object' => $ftp, 'ftp_remote_path' => $ftp_remote_path);
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
public function listfiles($match = 'backup_') {
[154] Fix | Delete
global $updraftplus;
[155] Fix | Delete
[156] Fix | Delete
$opts = $this->get_options();
[157] Fix | Delete
[158] Fix | Delete
$ftp = $this->getFTP(
[159] Fix | Delete
$opts['host'],
[160] Fix | Delete
$opts['user'],
[161] Fix | Delete
$opts['pass'],
[162] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_nossl'),
[163] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_disableverify'),
[164] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_useservercerts'),
[165] Fix | Delete
$opts['passive']
[166] Fix | Delete
);
[167] Fix | Delete
[168] Fix | Delete
if (is_wp_error($ftp)) return $ftp;
[169] Fix | Delete
[170] Fix | Delete
if (!$ftp->connect()) return new WP_Error('ftp_login_failed', sprintf(__("%s login failure", 'updraftplus'), 'FTP'));
[171] Fix | Delete
[172] Fix | Delete
$ftp_remote_path = $opts['path'];
[173] Fix | Delete
if ($ftp_remote_path) $ftp_remote_path = trailingslashit($ftp_remote_path);
[174] Fix | Delete
[175] Fix | Delete
$dirlist = $ftp->dir_list($ftp_remote_path);
[176] Fix | Delete
if (!is_array($dirlist)) return array();
[177] Fix | Delete
[178] Fix | Delete
$results = array();
[179] Fix | Delete
[180] Fix | Delete
foreach ($dirlist as $k => $path) {
[181] Fix | Delete
[182] Fix | Delete
if ($ftp_remote_path) {
[183] Fix | Delete
// Feb 2015 - found a case where the directory path was not prefixed on
[184] Fix | Delete
if (0 !== strpos($path, $ftp_remote_path) && (false !== strpos('/', $ftp_remote_path) && false !== strpos('\\', $ftp_remote_path))) continue;
[185] Fix | Delete
if (0 === strpos($path, $ftp_remote_path)) $path = substr($path, strlen($ftp_remote_path));
[186] Fix | Delete
// if (0 !== strpos($path, $ftp_remote_path)) continue;
[187] Fix | Delete
// $path = substr($path, strlen($ftp_remote_path));
[188] Fix | Delete
if (0 === strpos($path, $match)) $results[]['name'] = $path;
[189] Fix | Delete
} else {
[190] Fix | Delete
if ('/' == substr($path, 0, 1)) $path = substr($path, 1);
[191] Fix | Delete
if (false !== strpos($path, '/')) continue;
[192] Fix | Delete
if (0 === strpos($path, $match)) $results[]['name'] = $path;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
unset($dirlist[$k]);
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
// ftp_nlist() doesn't return file sizes. rawlist() does, but is tricky to parse. So, we get the sizes manually.
[199] Fix | Delete
foreach ($results as $ind => $name) {
[200] Fix | Delete
$size = $ftp->size($ftp_remote_path.$name['name']);
[201] Fix | Delete
if (0 === $size) {
[202] Fix | Delete
unset($results[$ind]);
[203] Fix | Delete
} elseif ($size>0) {
[204] Fix | Delete
$results[$ind]['size'] = $size;
[205] Fix | Delete
}
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
return $results;
[209] Fix | Delete
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
/**
[213] Fix | Delete
* Delete a single file from the service using FTP protocols
[214] Fix | Delete
*
[215] Fix | Delete
* @param Array $files - array of file names to delete
[216] Fix | Delete
* @param Array $ftparr - FTP details/credentials
[217] Fix | Delete
* @param Array $sizeinfo - unused here
[218] Fix | Delete
* @return Boolean|String - either a boolean true or an error code string
[219] Fix | Delete
*/
[220] Fix | Delete
public function delete($files, $ftparr = array(), $sizeinfo = array()) {// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- $sizeinfo unused
[221] Fix | Delete
[222] Fix | Delete
global $updraftplus;
[223] Fix | Delete
if (is_string($files)) $files = array($files);
[224] Fix | Delete
[225] Fix | Delete
$opts = $this->get_options();
[226] Fix | Delete
[227] Fix | Delete
if (is_array($ftparr) && isset($ftparr['ftp_object'])) {
[228] Fix | Delete
$ftp = $ftparr['ftp_object'];
[229] Fix | Delete
} else {
[230] Fix | Delete
$ftp = $this->getFTP(
[231] Fix | Delete
$opts['host'],
[232] Fix | Delete
$opts['user'],
[233] Fix | Delete
$opts['pass'],
[234] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_nossl'),
[235] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_disableverify'),
[236] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_useservercerts'),
[237] Fix | Delete
$opts['passive']
[238] Fix | Delete
);
[239] Fix | Delete
[240] Fix | Delete
if (is_wp_error($ftp) || !$ftp->connect()) {
[241] Fix | Delete
if (is_wp_error($ftp)) $updraftplus->log_wp_error($ftp);
[242] Fix | Delete
$this->log("Failure: we did not successfully log in with those credentials (host=".$opts['host'].").");
[243] Fix | Delete
return 'authentication_fail';
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
$ftp_remote_path = isset($ftparr['ftp_remote_path']) ? $ftparr['ftp_remote_path'] : trailingslashit($opts['path']);
[249] Fix | Delete
[250] Fix | Delete
$ret = true;
[251] Fix | Delete
foreach ($files as $file) {
[252] Fix | Delete
if (@$ftp->delete($ftp_remote_path.$file)) {// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[253] Fix | Delete
$this->log("delete: succeeded (${ftp_remote_path}${file})");
[254] Fix | Delete
} else {
[255] Fix | Delete
$this->log("delete: failed (${ftp_remote_path}${file})");
[256] Fix | Delete
$ret = 'file_delete_error';
[257] Fix | Delete
}
[258] Fix | Delete
}
[259] Fix | Delete
return $ret;
[260] Fix | Delete
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
public function download($file) {
[264] Fix | Delete
[265] Fix | Delete
global $updraftplus;
[266] Fix | Delete
[267] Fix | Delete
$opts = $this->get_options();
[268] Fix | Delete
[269] Fix | Delete
$ftp = $this->getFTP(
[270] Fix | Delete
$opts['host'],
[271] Fix | Delete
$opts['user'],
[272] Fix | Delete
$opts['pass'],
[273] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_nossl'),
[274] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_disableverify'),
[275] Fix | Delete
$updraftplus->get_job_option('updraft_ssl_useservercerts'),
[276] Fix | Delete
$opts['passive']
[277] Fix | Delete
);
[278] Fix | Delete
[279] Fix | Delete
if (is_wp_error($ftp)) {
[280] Fix | Delete
$this->log('Failure to get FTP object: '.$ftp->get_error_code().': '.$ftp->get_error_message());
[281] Fix | Delete
$this->log($ftp->get_error_message().' ('.$ftp->get_error_code().')', 'error');
[282] Fix | Delete
return false;
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
if (!$ftp->connect()) {
[286] Fix | Delete
$this->log('Failure: we did not successfully log in with those credentials.');
[287] Fix | Delete
$this->log(__('login failure', 'updraftplus'), 'error');
[288] Fix | Delete
return false;
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
// $ftp->make_dir(); we may need to recursively create dirs? TODO
[292] Fix | Delete
[293] Fix | Delete
$ftp_remote_path = trailingslashit($opts['path']);
[294] Fix | Delete
$fullpath = $updraftplus->backups_dir_location().'/'.$file;
[295] Fix | Delete
[296] Fix | Delete
$resume = false;
[297] Fix | Delete
if (file_exists($fullpath)) {
[298] Fix | Delete
$resume = true;
[299] Fix | Delete
$this->log("File already exists locally; will resume: size: ".filesize($fullpath));
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
return $ftp->get($fullpath, $ftp_remote_path.$file, FTP_BINARY, $resume, $updraftplus);
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
private function ftp_possible() {
[306] Fix | Delete
$funcs_disabled = array();
[307] Fix | Delete
foreach (array('ftp_connect', 'ftp_login', 'ftp_nb_fput') as $func) {
[308] Fix | Delete
if (!function_exists($func)) $funcs_disabled['ftp'][] = $func;
[309] Fix | Delete
}
[310] Fix | Delete
$funcs_disabled = apply_filters('updraftplus_ftp_possible', $funcs_disabled);
[311] Fix | Delete
return (0 == count($funcs_disabled)) ? true : $funcs_disabled;
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
/**
[315] Fix | Delete
* Get the pre configuration template
[316] Fix | Delete
*
[317] Fix | Delete
* @return String - the template
[318] Fix | Delete
*/
[319] Fix | Delete
public function get_pre_configuration_template() {
[320] Fix | Delete
[321] Fix | Delete
global $updraftplus_admin;
[322] Fix | Delete
global $updraftplus;
[323] Fix | Delete
[324] Fix | Delete
$classes = $this->get_css_classes(false);
[325] Fix | Delete
[326] Fix | Delete
?>
[327] Fix | Delete
<tr class="<?php echo $classes . ' ' . 'ftp_pre_config_container';?>">
[328] Fix | Delete
<td colspan="2">
[329] Fix | Delete
<h3><?php echo 'FTP'; ?></h3>
[330] Fix | Delete
<?php
[331] Fix | Delete
$possible = $this->ftp_possible();
[332] Fix | Delete
[333] Fix | Delete
if (is_array($possible)) {
[334] Fix | Delete
// Check requirements.
[335] Fix | Delete
global $updraftplus_admin;
[336] Fix | Delete
$trans = array(
[337] Fix | Delete
'ftp' => __('regular non-encrypted FTP', 'updraftplus'),
[338] Fix | Delete
'ftpsslimplicit' => __('encrypted FTP (implicit encryption)', 'updraftplus'),
[339] Fix | Delete
'ftpsslexplicit' => __('encrypted FTP (explicit encryption)', 'updraftplus')
[340] Fix | Delete
);
[341] Fix | Delete
foreach ($possible as $type => $missing) {
[342] Fix | Delete
$updraftplus_admin->show_double_warning('<strong>'.__('Warning', 'updraftplus').':</strong> '. sprintf(__("Your web server's PHP installation has these functions disabled: %s.", 'updraftplus'), implode(', ', $missing)).' '.sprintf(__('Your hosting company must enable these functions before %s can work.', 'updraftplus'), $trans[$type]), 'ftp');
[343] Fix | Delete
}
[344] Fix | Delete
}
[345] Fix | Delete
[346] Fix | Delete
?>
[347] Fix | Delete
[348] Fix | Delete
<em><?php echo '<p>' . apply_filters('updraft_sftp_ftps_notice', '<strong>'.htmlspecialchars(__('Only non-encrypted FTP is supported by regular UpdraftPlus.')).'</strong> <a href="'.$updraftplus->get_url('premium').'" target="_blank">'.__('If you want encryption (e.g. you are storing sensitive business data), then an add-on is available in the Premium version.', 'updraftplus')).'</a></p>'; ?></em>
[349] Fix | Delete
</td>
[350] Fix | Delete
</tr>
[351] Fix | Delete
[352] Fix | Delete
<?php
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
/**
[356] Fix | Delete
* Get the configuration template
[357] Fix | Delete
*
[358] Fix | Delete
* @return String - the template, ready for substitutions to be carried out
[359] Fix | Delete
*/
[360] Fix | Delete
public function get_configuration_template() {
[361] Fix | Delete
[362] Fix | Delete
ob_start();
[363] Fix | Delete
[364] Fix | Delete
$classes = $this->get_css_classes();
[365] Fix | Delete
[366] Fix | Delete
?>
[367] Fix | Delete
[368] Fix | Delete
<tr class="<?php echo $classes;?>">
[369] Fix | Delete
<th><?php _e('FTP server', 'updraftplus');?>:</th>
[370] Fix | Delete
<td><input class="updraft_input--wide" type="text" size="40" data-updraft_settings_test="server" <?php $this->output_settings_field_name_and_id('host');?> value="{{host}}" /></td>
[371] Fix | Delete
</tr>
[372] Fix | Delete
[373] Fix | Delete
<tr class="<?php echo $classes;?>">
[374] Fix | Delete
<th><?php _e('FTP login', 'updraftplus');?>:</th>
[375] Fix | Delete
<td><input class="updraft_input--wide" type="text" size="40" data-updraft_settings_test="login" <?php $this->output_settings_field_name_and_id('user');?> value="{{user}}" /></td>
[376] Fix | Delete
</tr>
[377] Fix | Delete
[378] Fix | Delete
<tr class="<?php echo $classes;?>">
[379] Fix | Delete
<th><?php _e('FTP password', 'updraftplus');?>:</th>
[380] Fix | Delete
<td><input class="updraft_input--wide" type="<?php echo apply_filters('updraftplus_admin_secret_field_type', 'password'); ?>" size="40" data-updraft_settings_test="pass" <?php $this->output_settings_field_name_and_id('pass');?> value="{{pass}}" /></td>
[381] Fix | Delete
</tr>
[382] Fix | Delete
[383] Fix | Delete
<tr class="<?php echo $classes;?>">
[384] Fix | Delete
<th><?php _e('Remote path', 'updraftplus');?>:</th>
[385] Fix | Delete
<td><input title="<?php _e('Needs to already exist', 'updraftplus'); ?>" class="updraft_input--wide" type="text" size="64" data-updraft_settings_test="path" <?php $this->output_settings_field_name_and_id('path');?> value="{{path}}" /> <em><?php _e('Needs to already exist', 'updraftplus');?></em></td>
[386] Fix | Delete
</tr>
[387] Fix | Delete
[388] Fix | Delete
<tr class="<?php echo $classes;?>">
[389] Fix | Delete
<th><?php _e('Passive mode', 'updraftplus');?>:</th>
[390] Fix | Delete
<td>
[391] Fix | Delete
<input title="<?php echo __('Almost all FTP servers will want passive mode; but if you need active mode, then uncheck this.', 'updraftplus');?>" type="checkbox" data-updraft_settings_test="passive" <?php $this->output_settings_field_name_and_id('passive');?> value="1" {{#ifeq '1' passive}}checked="checked"{{/ifeq}}> <br><em><?php echo __('Almost all FTP servers will want passive mode; but if you need active mode, then uncheck this.', 'updraftplus');?></em></td>
[392] Fix | Delete
</tr>
[393] Fix | Delete
[394] Fix | Delete
<?php
[395] Fix | Delete
[396] Fix | Delete
echo $this->get_test_button_html('FTP');
[397] Fix | Delete
[398] Fix | Delete
return ob_get_clean();
[399] Fix | Delete
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
/**
[403] Fix | Delete
* Perform a test of user-supplied credentials, and echo the result
[404] Fix | Delete
*
[405] Fix | Delete
* @param Array $posted_settings - settings to test
[406] Fix | Delete
*/
[407] Fix | Delete
public function credentials_test($posted_settings) {
[408] Fix | Delete
[409] Fix | Delete
$server = $posted_settings['server'];
[410] Fix | Delete
$login = $posted_settings['login'];
[411] Fix | Delete
$pass = $posted_settings['pass'];
[412] Fix | Delete
$path = $posted_settings['path'];
[413] Fix | Delete
$nossl = $posted_settings['nossl'];
[414] Fix | Delete
$passive = empty($posted_settings['passive']) ? false : true;
[415] Fix | Delete
[416] Fix | Delete
$disable_verify = $posted_settings['disableverify'];
[417] Fix | Delete
$use_server_certs = $posted_settings['useservercerts'];
[418] Fix | Delete
[419] Fix | Delete
if (empty($server)) {
[420] Fix | Delete
_e('Failure: No server details were given.', 'updraftplus');
[421] Fix | Delete
return;
[422] Fix | Delete
}
[423] Fix | Delete
if (empty($login)) {
[424] Fix | Delete
printf(__('Failure: No %s was given.', 'updraftplus'), __('login', 'updraftplus'));
[425] Fix | Delete
return;
[426] Fix | Delete
}
[427] Fix | Delete
if (empty($pass)) {
[428] Fix | Delete
printf(__('Failure: No %s was given.', 'updraftplus'), __('password', 'updraftplus'));
[429] Fix | Delete
return;
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
if (preg_match('#ftp(es|s)?://(.*)#i', $server, $matches)) $server = untrailingslashit($matches[2]);
[433] Fix | Delete
[434] Fix | Delete
// $ftp = $this->getFTP($server, $login, $pass, $nossl, $disable_verify, $use_server_certs);
[435] Fix | Delete
$ftp = $this->getFTP($server, $login, $pass, $nossl, $disable_verify, $use_server_certs, $passive);
[436] Fix | Delete
[437] Fix | Delete
if (!$ftp->connect()) {
[438] Fix | Delete
_e('Failure: we did not successfully log in with those credentials.', 'updraftplus');
[439] Fix | Delete
return;
[440] Fix | Delete
}
[441] Fix | Delete
// $ftp->make_dir(); we may need to recursively create dirs? TODO
[442] Fix | Delete
[443] Fix | Delete
$file = md5(rand(0, 99999999)).'.tmp';
[444] Fix | Delete
$fullpath = trailingslashit($path).$file;
[445] Fix | Delete
[446] Fix | Delete
if ($ftp->put(ABSPATH.WPINC.'/version.php', $fullpath, FTP_BINARY, false, true)) {
[447] Fix | Delete
echo __("Success: we successfully logged in, and confirmed our ability to create a file in the given directory (login type:", 'updraftplus')." ".$ftp->login_type.')';
[448] Fix | Delete
@$ftp->delete($fullpath);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[449] Fix | Delete
} else {
[450] Fix | Delete
_e('Failure: we successfully logged in, but were not able to create a file in the given directory.', 'updraftplus');
[451] Fix | Delete
if (!empty($ftp->ssl)) {
[452] Fix | Delete
echo ' '.__('This is sometimes caused by a firewall - try turning off SSL in the expert settings, and testing again.', 'updraftplus');
[453] Fix | Delete
}
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
/**
[459] Fix | Delete
* Check whether options have been set up by the user, or not
[460] Fix | Delete
*
[461] Fix | Delete
* @param Array $opts - the potential options
[462] Fix | Delete
*
[463] Fix | Delete
* @return Boolean
[464] Fix | Delete
*/
[465] Fix | Delete
public function options_exist($opts) {
[466] Fix | Delete
if (is_array($opts) && !empty($opts['host']) && isset($opts['user']) && '' != $opts['user']) return true;
[467] Fix | Delete
return false;
[468] Fix | Delete
}
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function