Welcome Guest, Not a member yet? Register   Sign In
[function.ftp-get]: failed to open stream: Permission denied

[eluser]Jay Logan[/eluser]
I'm trying to download some remote files with the FTP library extension by Phil S. but I keep getting this error.

A PHP Error was encountered

Severity: Warning

Message: ftp_get(/home/user/tmp/awstats.domain.com.conf) [function.ftp-get]: failed to open stream: Permission denied

Filename: libraries/MY_Ftp.php

Line Number: 22

The error obviously explains what the problem is but I don't know how to fix it. I've CHMOD the folders and files to 777 and other variations to see if that would help. It didn't.

Any thoughts?

You're probably using the wrong username/password or that user doesn't have access to the folder.

[eluser]Jay Logan[/eluser]
Well the user name / password works in FileZilla and it actually works with the FTP library because it reads the directory and loops through the files correctly.

$config['hostname'] = "www.hostdomain.com";
$config['username'] = "username";
$config['password'] = "password";
$config['debug'] = TRUE;


$files = $this->ftp->list_files('/tmp/awstats');


foreach ($files as $file) {

$this->ftp->download('/tmp/awstats/'.$file, '/home/localusername/tmp/'.$file, 'ASCII', 0755);



[eluser]Phil Sturgeon[/eluser]
function download($rempath, $locpath, $mode = 'auto')

I think you are looking at the ftp_get() parameters and not the parameters for the FTP::download() method.

$this->ftp->download('/home/localusername/tmp/'.$file, '/tmp/awstats/'.$file, 'ASCII', 0755);
chmod('/tmp/awstats/'.$file, 0755);

Something like that should do the trick.

[eluser]Jay Logan[/eluser]
I tried it your way and got this error instead.

Message: ftp_get(/home/user/tmp/awstats.domain.com.conf) [function.ftp-get]: failed to open stream: No such file or directory

Which leads me to believe the original parameters were correct.

[eluser]Phil Sturgeon[/eluser]
You may well be right. It threw me when I saw ", 0755". This function swaps the 1st and 2nd param to the opposite order of ftp_get().

I haven't used this in ages, but remember that full server paths aren't always the same as full FTP paths.

[eluser]Jay Logan[/eluser]
Solved. Had to rethink my strategy and came up with this ugly, yet functional solution. The problem was I was moving 300 accounts over to a dedicated server. Although HostGator offers a transfer server, they tend to ignore .htaccess files and I also needed to update my local DB with the new log in info and server IP addresses. Plus I wanted to transfer my AWStats. Here is what I came up with.

$this->load->library(array('ftp', 'whm'));

$site_id = $this->sites_model->get_random_active_site();

if ($site_id) {

$site_info = $this->sites_model->get_info(array('id' => $site_id));

$cpanel_parameters = array(

'ip' => 'n',
'cgi' => 'n',
'frontpage' => 'n',
'cpmod' => 'x3',
'useregns' => '0',
'reseller' => '0',
'domain' => str_replace('http://www.', '', $site_info['url']),
'customip' => $ip_address,
'username' => $site_info['cpanel_user_name'],
'password' => 'charlo2010',
'plan' => 'dealer_site',
'contactemail' => '[email protected]'


$new_account = $this->whm->createAccount($cpanel_parameters);

if ($new_account->result->status == 1) {

$config1['hostname'] = "www.old-domain.com";
$config1['username'] = $site_info['cpanel_user_name'];
$config1['password'] = "oldpassword";
$config1['debug'] = TRUE;


$awstats = $this->ftp->list_files('/tmp/awstats');


foreach ($awstats as $file) {

$this->ftp->download('/tmp/awstats/'.$file, $file, 'ASCII', 0755);



$config2['hostname'] = "www.new-domain.com";
$config2['username'] = $site_info['cpanel_user_name'];
$config2['password'] = "newpassword";
$config2['debug'] = TRUE;


$this->ftp->upload('/home/username/public_html/.htaccess', '/public_html/.htaccess', 'ASCII', 0644);
$this->ftp->upload('/home/username/public_html/new_account_index.php', '/public_html/index.php', 'ASCII', 0644);

$this->ftp->mkdir('/tmp/awstats/', 0755);

foreach ($awstats as $file) {

$this->ftp->upload('/home/username/public_html/'.$file, '/tmp/awstats/'.$file, 'ASCII', 0644);




echo "Site converted.";

} else {



} else {

echo "DONE";


Theme © iAndrew 2016 - Forum software by © MyBB