Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 855101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:01:37+00:00 2026-05-15T08:01:37+00:00

I’m trying to access an FTP server from my PHP script using Codeigniter’s FTP

  • 0

I’m trying to access an FTP server from my PHP script using Codeigniter’s FTP Library. These functions work great, but when testing the script I discovered that if I attempt to connect to a server that does not exist, the script does not terminate with an error message of any kind.

The page continues to execute, until the web server gives up, returning an empty document.

So I am wondering, is there a way to limit the amount of time that Codeigniter can try to connect to an FTP server, then display a message if that times out?

I tried using the php function set_time_limit(), but it does not behave how I expected it to.

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:01:38+00:00Added an answer on May 15, 2026 at 8:01 am

    Codeigniter’s ftp class uses the underlying ftp_connect php call that supports a 3rd optional parameter, timeout (https://www.php.net/manual/en/function.ftp-connect.php).

    Codeigniter however does not use it, but allows for extending the default libraries it provides (providing that you’re willing to do some work and check that any updates you do to the core will not break the functionality of your extended class). So to solve your problem you could create a new library in you application library folder:

    <?php
    
    class MY_FTP extends CI_FTP { //Assuming that in your config.php file, your subclass prefix is set to 'MY_' like so: $config['subclass_prefix'] = 'MY_';
        
        var $timeout = 90;
        /**
         * FTP Connect
         *
         * @access  public
         * @param   array    the connection values
         * @return  bool
         */
        function connect($config = array())
        {
            if (count($config) > 0)
            {
                $this->initialize($config);
            }
            
            if (FALSE === ($this->conn_id = ftp_connect($this->hostname, $this->port, $this->timeout)))
            {
                if ($this->debug == TRUE)
                {
                    $this->_error('ftp_unable_to_connect');
                }
                return FALSE;
            }
    
            if ( ! $this->_login())
            {
                if ($this->debug == TRUE)
                {
                    $this->_error('ftp_unable_to_login');
                }
                return FALSE;
            }
    
            // Set passive mode if needed
            if ($this->passive == TRUE)
            {
                ftp_pasv($this->conn_id, TRUE);
            }
    
            return TRUE;
        }
    }
    ?>
    

    and from your script, you could add to your configuration array the timeout option:

    $this->load->library('ftp'); //if ftp is not autoloaded
    $ftp_params = array('hostname'=>'1.2.3.4', 'port'=>21, 'timeout'=>10); //timout is 10 seconds instead of default 90
    $ftp_conn = $this->ftp->connect($ftp_params);
    if(FALSE === $ftp_conn) {
    //Code to handle error
    }
    

    The ftp class is not designed to give error messages unless the debug parameter is set to TRUE in te config array, in which case it’ll just display an error. However it can also be override, because all errors call the function _error() in the class. So you could set ‘debug’ => true in your $ftp_params array, and add a function in MY_ftp like so:

    /**
     * This function overrides 
     */
    function _error($line)
    {
        $this->error = $line;
    }
    

    And then have a function getError()
    /**
    * This function overrides
    */
    function get_error()
    {
    return $this->error;
    }

    So if

    $ftp_conn = $this->ftp->connect($ftp_params);
    

    returns false, you can call

    $error = $this->ftp->get_error();
    

    to get your error and display it.
    Now, you can always customize and have a more complex error handling mechanism by further customizing the class…

    Hope it answers your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.