2
votes

I am trying to connect to my FTP server using CodeIgniter FTP Class. What I want to do is to just display a success message when the connection is successful and display an error message if an error occurs. I have found that the $this->ftp->connect() function returns 1 for successful connection. But when an error occurs it takes me to the error page instead of displaying the error message.

enter image description here

Here is my code:

$this->load->library('ftp');
$config['hostname'] = 'ftp.example.com';
$config['username'] = 'your-username';
$config['password'] = 'your-password';
$config['debug']    = TRUE;
if ($this->ftp->connect($config)) {
    echo "success!";
} else {
    echo "error!";
}

Any suggestion on how I can handle this error will be really helpful.

1
Who is your ftp provider? make sure to add $config['port'] = ; - Ilanus
@Ilan Hasanov: my ftp provider is orgfree.com and my code is using the default port 21 as $config['port'] is not defined. - S.K
And you are successfully connected to your FTP before with the same credentials? is this SFTP or FTP? - Ilanus
I am connecting using ftp. The error occurs in the event of wrong password. - S.K

1 Answers

1
votes

You can display the error message just by turning off the debug option.

$config['debug'] = FALSE;