PHP ftp_connect() Function
Definition and Usage
The ftp_connect() function establishes a new FTP connection.
If successful, it returns a connection identifier, otherwise it returns false.
Syntax
ftp_connect(host,port,timeout)
Parameter | Description |
---|---|
host |
Required. Specifies the FTP server to connect to. It can be a domain name or an IP address. Should not end with a slash and does not need to start with ftp://. |
port | Optional. Specifies the port for the FTP server. |
timeout | Optional. Specifies the timeout time for the FTP server. The default is 90 seconds. |
Description
Tip:The timeout time can be changed and retrieved at any time through the function ftp_set_option() and ftp_get_option() to change and retrieve.
Parameter timeout Only applicable to PHP 4.2.0 and above versions.
Example
This example attempts to connect to an FTP server. If the connection fails, the die() function will terminate the script and output a message:
<?php $conn = ftp_connect("ftp.testftp.com") or die("Could not connect"); ?>