WP_Filesystem_ftpsockets::connect
Connects filesystem.
Метод класса: WP_Filesystem_ftpsockets{}
Хуков нет.
Возвращает
bool. True on success, false on failure.
Использование
$WP_Filesystem_ftpsockets = new WP_Filesystem_ftpsockets(); $WP_Filesystem_ftpsockets->connect();
Список изменений
| С версии 2.5.0 | Введена. |
Код WP_Filesystem_ftpsockets::connect() WP Filesystem ftpsockets::connect WP 7.1.2
public function connect() {
/*
* Bail if the constructor recorded a configuration error. Connection and
* authentication errors are excluded so that a failed connection attempt
* can be retried on the same instance.
*/
if ( $this->errors->has_errors() && ! array_intersect( array( 'connect', 'auth' ), $this->errors->get_error_codes() ) ) {
return false;
}
if ( ! $this->ftp ) {
return false;
}
$this->ftp->SetTimeout( FS_CONNECT_TIMEOUT );
if ( ! $this->ftp->SetServer( $this->options['hostname'], $this->options['port'] ) ) {
$this->errors->add(
'connect',
sprintf(
/* translators: %s: hostname:port */
__( 'Failed to connect to FTP Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
return false;
}
if ( ! $this->ftp->connect() ) {
$this->errors->add(
'connect',
sprintf(
/* translators: %s: hostname:port */
__( 'Failed to connect to FTP Server %s' ),
$this->options['hostname'] . ':' . $this->options['port']
)
);
return false;
}
if ( ! $this->ftp->login( $this->options['username'], $this->options['password'] ) ) {
$this->errors->add(
'auth',
sprintf(
/* translators: %s: Username. */
__( 'Username/Password incorrect for %s' ),
$this->options['username']
)
);
return false;
}
$this->ftp->SetType( FTP_BINARY );
$this->ftp->Passive( true );
$this->ftp->SetTimeout( FS_TIMEOUT );
return true;
}