PHP ftp_get_option() Function
The PHP ftp_get_option() function returns the value for the requested option from the specified FTP connection.
Syntax
ftp_get_option(ftp, option)
Parameters
ftp |
Required. Specify the FTP connection to use. |
option |
Required. Specify the runtime option to return. Possible options are:
|
Return Value
Returns the value on success or false if the given option is not supported. In the latter case, a warning message is also thrown.
Example:
The example below shows the usage of ftp_get_option() function.
<?php //FTP server to use $ftp_server = "ftp.example.com"; //username for the FTP Connection $ftp_user = "user"; //password for the user $ftp_pass = "password"; //set up a connection or die $ftp = ftp_connect($ftp_server) or die("Could not connect to $ftp_server"); if($ftp) { echo "Successfully connected to $ftp_server!\n"; //trying to login if(@ftp_login($ftp, $ftp_user, $ftp_pass)) { echo "Connected as $ftp_user@$ftp_server\n"; //displaying timeout for the ftp connection echo "FTP_TIMEOUT_SEC : " .ftp_get_option($ftp, FTP_TIMEOUT_SEC)."\n"; //displaying whether FTP_AUTOSEEK enabled or not echo "FTP_AUTOSEEK : " .ftp_get_option($ftp, FTP_AUTOSEEK)."\n"; } else { echo "Couldn't connect as $ftp_user\n"; } //close the connection if(ftp_close($ftp)) { echo "Connection closed successfully!\n"; } } ?>
The output of the above code will be:
Successfully connected to ftp.example.com! Connected as user@ftp.example.com FTP_TIMEOUT_SEC : 90 FTP_AUTOSEEK : 1 Connection closed successfully!
❮ PHP FTP Reference