From 10cd9df0aed611f1478249b4e06f9c18fad18a40 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 15 Aug 2009 12:01:04 +0000 Subject: [PATCH] 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 --- wp-admin/includes/class-wp-filesystem-ftpext.php | 12 +++++++++--- wp-admin/includes/class-wp-filesystem-ftpsockets.php | 5 +++-- wp-admin/includes/class-wp-filesystem-ssh2.php | 10 +--------- wp-admin/includes/file.php | 6 ++++++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index d4ad8132be..db9e307d79 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -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; } diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index 759eaa821c..3f0b74fd55 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -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; } diff --git a/wp-admin/includes/class-wp-filesystem-ssh2.php b/wp-admin/includes/class-wp-filesystem-ssh2.php index 604b86cc41..d406106b50 100644 --- a/wp-admin/includes/class-wp-filesystem-ssh2.php +++ b/wp-admin/includes/class-wp-filesystem-ssh2.php @@ -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 ); diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 5b93b8fe2c..5c6a0260da 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -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;