PHP ftp_connect() Function

Definition and Usage

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 neither should it start with ftp://.

port Optional. Specifies the port of 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 get.

Parameter timeout Only for PHP 4.2.0 and above versions.

Example

This example tries 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");
?>