w3resource

PHP: ftp_connect() function

Description

The ftp_connect() function opens an FTP connection to a server.

Version:

(PHP 4 and above)

Syntax:

ftp_connect(host, port, timeout)

Parameters:

Name Description Required /
Optional
Type
host The address of FTP server. This parameter shouldn't be suffixed with trailing slashes and shouldn't be prefixed with ftp://. Required string
port Specifies a port number other than default ftp port 21. If not set or set to zero port 21 is used. Optional integer
timeout Specifies the timeout other than default value 90 seconds for all subsequent network operations. If not set , the default value is 90 seconds. Optional integer

Return value:

Returns an FTP stream on success or FALSE on error.

Value Type: Resource.

Example:

<?php
$ftp_server="192.168.0.2";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 
if (!ftp_connect($ftp_server))
echo "not connected";
else
echo "successful connected";
?>

Output:

successful connected

See also

PHP Function Reference

Previous: ftp_close
Next: ftp_delete



Follow us on Facebook and Twitter for latest update.