PHP ftp connect

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. $ftp_server="192.168.0.2";  

  2. $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");   

  3. if (!ftp_connect($ftp_server))  

  4. echo "not connected";  

  5. else  

  6. echo "successful connected";  

  7. ?>  

Output :

successful connected