ftp_get_option() function in PHP

The ftp_get_option() function retrieves runtime configuration options for an established FTP connection, allowing you to check current settings like timeout values and autoseek behavior.

Syntax

ftp_get_option(connection, option);

Parameters

  • connection − The FTP connection resource returned by ftp_connect().

  • option − The runtime option to retrieve. Available constants:

    • FTP_TIMEOUT_SEC − Returns the current network timeout in seconds

    • FTP_AUTOSEEK − Returns TRUE if autoseek is enabled, FALSE otherwise

Return Value

Returns the option value on success, or FALSE if the specified option is not supported or the connection is invalid.

Example

The following example demonstrates how to retrieve FTP connection options ?

<?php
    $ftp_server = "ftp.example.com";
    $ftp_user = "username";
    $ftp_pass = "password";
    
    // Establish FTP connection
    $connection = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
    $login = ftp_login($connection, $ftp_user, $ftp_pass);
    
    if ($login) {
        // Get current timeout setting
        $timeout = ftp_get_option($connection, FTP_TIMEOUT_SEC);
        echo "Current timeout: " . $timeout . " seconds<br>";
        
        // Check autoseek setting
        $autoseek = ftp_get_option($connection, FTP_AUTOSEEK);
        echo "Autoseek enabled: " . ($autoseek ? "Yes" : "No") . "<br>";
    }
    
    ftp_close($connection);
?>

Output

Current timeout: 90 seconds
Autoseek enabled: Yes

Conclusion

The ftp_get_option() function is useful for checking current FTP connection settings, helping you monitor timeout values and autoseek behavior for debugging or configuration purposes.

Updated on: 2026-03-15T07:40:09+05:30

187 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements