Add constants for ftp connections timeouts, props dd32, see #10522

git-svn-id: https://develop.svn.wordpress.org/trunk@11823 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2009-08-15 12:01:04 +00:00
parent 5e8dbc10cd
commit 10cd9df0ae
4 changed files with 19 additions and 14 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 );

View File

@ -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;