Index: ext/ftp/ftp.c =================================================================== RCS file: /repository/php-src/ext/ftp/ftp.c,v retrieving revision 1.112.2.3 diff -u -p -d -r1.112.2.3 ftp.c --- ext/ftp/ftp.c 1 Jan 2006 12:50:06 -0000 1.112.2.3 +++ ext/ftp/ftp.c 24 Jan 2006 00:13:41 -0000 @@ -241,6 +241,7 @@ ftp_quit(ftpbuf_t *ftp) int ftp_login(ftpbuf_t *ftp, const char *user, const char *pass TSRMLS_DC) { + int errcode; #if HAVE_OPENSSL_EXT SSL_CTX *ctx = NULL; #endif @@ -291,13 +292,27 @@ ftp_login(ftpbuf_t *ftp, const char *use } SSL_set_fd(ftp->ssl_handle, ftp->fd); - - if (SSL_connect(ftp->ssl_handle) <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS handshake failed"); - SSL_shutdown(ftp->ssl_handle); - return 0; - } - + + do { + errcode = SSL_connect(ftp->ssl_handle); + switch (SSL_get_error (ftp->ssl_handle, errcode)) { + case SSL_ERROR_NONE: + errcode = 1; + break; + case SSL_ERROR_WANT_WRITE: + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_X509_LOOKUP: + errcode = 0; + break; + default: + /* true error happened */ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS handshake failed"); + SSL_shutdown(ftp->ssl_handle); + return 0; + break; + } + } while(errcode == 0 && !SSL_is_init_finished(ftp->ssl_handle)); + ftp->ssl_active = 1; if (!ftp->old_ssl) {