Syntax:ftp_set_option ($ftp_connection, $option, $value)
Parameter:This function takes three parameter as above and described below:
- $ftp_connection:Required. Indicates an existing FTP connection.
- $option:required. Specifies a runtime parameter to set for an existing FTP connection.
Possible Values $option: - FTP_TIMEOUT_SEC: Returns the timeout used for the network.
- FTP_AUTOSEEK: It is enabled by default. Returns TRUE if this option is enabled, otherwise returns FALSE.
- FTP_USEPASVADDRESS: If set to FALSE, PHP ignores the IP address returned by the FTP server in response to the PASV command and uses the IP address instead. address as a parameter to the ftp_connect() function.
- $value:This parameter is required. Specifies the value of the option in the previous parameter.
Returned value: - On success:returns TRUE, i.e. the option can be set.
- On failure:returns FALSE. A warning is also generated.
Notes : - This function is available for PHP 4.2.0 and above.
- 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.
Example :
/ / Connect to FTP server
// Use correct FTP server
$ftp_server
=
"localhost"
;
// use correct ftp username
$ftp_username
=
"user"
;
// Use correct FTP password matching
// to the ftp username
$ftp_userpass
=
"user"
;
// Setting up 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!"
;
// Login to the established connection with
// ftp user password
$login
= ftp_login (
$ftp_connection
,
$ftp_username
,
$ftp_userpass
);
if
(
$login
) {
// Success check login
echo
"
logged in successfully!
"
;
// Print setup successfully
// for current ftp connection
echo
ftp_set_option (
$ftp_connection
,
FTP_TIMEOUT_SEC, 120);
}
else
{
echo
"
login failed!"
;
}
// Close connection
if
(ftp_close (
$ftp_connection
)) {
echo
"
Connection closed Successfully!"
;
}
}
?>
Output:successfully connected to the ftp server! logged in successfully! 1 Connection closed Successfully!
Link: https://www.php.net/manual/en/function.ftp-set-option.php