Change language

PHP ftp_connect () function

Syntax:
ftp_connect ($ftp_host, $ftp_port, $timeout); 
Parameter:this function takes three parameters as above and described below:
  • $ftp_host:This is a required parameter and is used to specify the hostname or ftp server to connect to. It can be a domain name or an IP address, and these addresses must not be prefixed with "ftp: //" or must not have a slash at the end of this URL.
  • $ftp_port: this is an optional parameter. It specifies the port number to connect. If not specified, the default FTP port number is used. The default FTP port number is - 21.
  • $timeout:This is an optional parameter. It specifies the waiting time for all subsequent network operations. If this parameter is not specified, the default is 90 seconds.
Note.The timeout can be requested or changed at any time using ftp_get_option() and ftp_set_option() respectively.Return Value:Returns FTP stream on success or False on error.Notes:
  • This function is available for PHP 4.0.0 and newer.
  • The following examples cannot be run in the online IDE. So try running PHP on some hosting server or localhost with the correct ftp server name.
The following programs illustrate the ftp_connect() function in PHP:Example 1:  
// Connect to the FTP server $ftp_server = "localhost" ;  
// Establish FTP connection $ftp_connection = ftp_connect ( $ftp_server ) or die ( "Could not connect to $ftp_server" ); if ( $ftp_connection ) { echo "Successfully connected to the ftp server!" ; // Close the connection ftp_close ( $ftp_connection ); }  
?>
Output:
Successfully connected to the ftp server! 
Example 2.Connecting to the ftp server on port 21.  
// Connect to the FTP server $ftp_server = "localhost" ;  
// Establish FTP connection $ftp_connection = ftp_connect ( $ftp_server , 21) or die ( "Could not connect to $ftp_server" );  
// port 21 is used as the second parameter
// in the ftp_connect() function if ( $ftp_connection ) { echo "Successfully connected to the ftp server!" ; // Close the connection ftp_close ( $ftp_connection ); }  
?>
Output:
Successfully connected to the ftp server! 
Link: https://www.php.net/manual/en/function.ftp-connect.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method