ftp_connect

FunctionReturn type changed in PHP 8.1

Opens an FTP connection.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
Improved
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

ftp_connect Function synopsis

ftp_connect(
    string $hostname,
    int $port = 21,
    int $timeout = 90
  ): FTP\Connection|false

Parameters

$hostname

Typestring

The FTP server address. This parameter shouldn't have any trailing slashes and shouldn't be prefixed with ftp://.

$port

OptionalTypeintDefault value21

This parameter specifies an alternate port to connect to. If it is omitted or set to zero, then the default FTP port, 21, will be used.

$timeout

OptionalTypeintDefault value90

This parameter specifies the timeout in seconds for all subsequent network operations. If omitted, the default value is 90 seconds. The timeout can be changed and queried at any time with ftp_set_option and ftp_get_option.

Return value

TypeFTP\Connection|false

Returns an FTP\Connection instance on success, or false on failure.

Changes to the ftp_connect Function

PHP 8.1

  • Return type added: FTP\Connection|false
  ftp_connect(
      string $hostname,
      int $port = 21,
      int $timeout = 90
-   )
+   ): FTP\Connection|false

PHP 8.0

  • Parameter name of parameter #1 changed: $host to $hostname
  • Parameter type added for parameter #1 ($hostname): string
  • Parameter type added for parameter #2 ($port): int
  • Parameter default value added for position #2 ($port): 21
  • Parameter type added for parameter #3 ($timeout): int
  • Parameter default value added for position #3 ($timeout): 90
  ftp_connect(
-     $host,
+     string $hostname,
-     $port,
+     int $port = 21,
-     $timeout
+     int $timeout = 90
    )

ftp_connect Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes