Add constants for ftp connections timeouts, props dd32, see #10522
git-svn-id: http://svn.automattic.com/wordpress/trunk@11823 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
42471b4882
commit
ca27f326a9
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
||||
var $link;
|
||||
var $timeout = 5;
|
||||
var $errors = null;
|
||||
var $options = array();
|
||||
|
||||
|
@ -33,6 +32,11 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
|||
}
|
||||
|
||||
// Set defaults:
|
||||
//This Class uses the timeout on a per-connection basis, Others use it on a per-action basis.
|
||||
|
||||
if ( ! defined('FS_TIMEOUT') )
|
||||
define('FS_TIMEOUT', 240);
|
||||
|
||||
if ( empty($opt['port']) )
|
||||
$this->options['port'] = 21;
|
||||
else
|
||||
|
@ -64,9 +68,9 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
|||
|
||||
function connect() {
|
||||
if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') )
|
||||
$this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], $this->timeout);
|
||||
$this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
|
||||
else
|
||||
$this->link = @ftp_connect($this->options['hostname'], $this->options['port'], $this->timeout);
|
||||
$this->link = @ftp_connect($this->options['hostname'], $this->options['port'], FS_CONNECT_TIMEOUT);
|
||||
|
||||
if ( ! $this->link ) {
|
||||
$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
|
||||
|
@ -80,6 +84,8 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
|||
|
||||
//Set the Connection to use Passive FTP
|
||||
@ftp_pasv( $this->link, true );
|
||||
if ( @ftp_get_option($this->link, FTP_TIMEOUT_SEC) < FTP_TIMEOUT )
|
||||
@ftp_set_option($this->link, FTP_TIMEOUT_SEC, FTP_TIMEOUT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
||||
var $ftp = false;
|
||||
var $timeout = 5;
|
||||
var $errors = null;
|
||||
var $options = array();
|
||||
|
||||
|
@ -61,12 +60,13 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
|||
if ( ! $this->ftp )
|
||||
return false;
|
||||
|
||||
//$this->ftp->Verbose = true;
|
||||
$this->ftp->setTimeout(FS_CONNECT_TIMEOUT);
|
||||
|
||||
if ( ! $this->ftp->SetServer($this->options['hostname'], $this->options['port']) ) {
|
||||
$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $this->ftp->connect() ) {
|
||||
$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
|
||||
return false;
|
||||
|
@ -79,6 +79,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
|||
|
||||
$this->ftp->SetType(FTP_AUTOASCII);
|
||||
$this->ftp->Passive(true);
|
||||
$this->ftp->setTimeout(FS_TIMEOUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,14 +45,6 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
|
|||
var $link = false;
|
||||
var $sftp_link = false;
|
||||
var $keys = false;
|
||||
/*
|
||||
* This is the timeout value for ssh results.
|
||||
* Slower servers might need this incressed, but this number otherwise should not change.
|
||||
*
|
||||
* @parm $timeout int
|
||||
*
|
||||
*/
|
||||
var $timeout = 15;
|
||||
var $errors = array();
|
||||
var $options = array();
|
||||
|
||||
|
@ -148,7 +140,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
|
|||
$this->errors->add('command', sprintf(__('Unable to perform command: %s'), $command));
|
||||
} else {
|
||||
stream_set_blocking( $stream, true );
|
||||
stream_set_timeout( $stream, $this->timeout );
|
||||
stream_set_timeout( $stream, FS_TIMEOUT );
|
||||
$data = stream_get_contents( $stream );
|
||||
fclose( $stream );
|
||||
|
||||
|
|
|
@ -605,6 +605,12 @@ function WP_Filesystem( $args = false, $context = false ) {
|
|||
|
||||
$wp_filesystem = new $method($args);
|
||||
|
||||
//Define the timeouts for the connections. Only available after the construct is called to allow for per-transport overriding of the default.
|
||||
if ( ! defined('FS_CONNECT_TIMEOUT') )
|
||||
define('FS_CONNECT_TIMEOUT', 30);
|
||||
if ( ! defined('FS_TIMEOUT') )
|
||||
define('FS_TIMEOUT', 30);
|
||||
|
||||
if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
|
||||
return false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue