CodeIgniter Forums
[function.ftp-get]: failed to open stream: Permission denied - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: [function.ftp-get]: failed to open stream: Permission denied (/thread-29493.html)



[function.ftp-get]: failed to open stream: Permission denied - El Forum - 04-11-2010

[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.

Code:
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?


[function.ftp-get]: failed to open stream: Permission denied - El Forum - 04-11-2010

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


[function.ftp-get]: failed to open stream: Permission denied - El Forum - 04-12-2010

[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.

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

$this->ftp->connect($config);

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

unset($files[0]);
unset($files[1]);

foreach ($files as $file) {

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

}

$this->ftp->close();



[function.ftp-get]: failed to open stream: Permission denied - El Forum - 04-12-2010

[eluser]Phil Sturgeon[/eluser]
Code:
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.

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

Something like that should do the trick.


[function.ftp-get]: failed to open stream: Permission denied - El Forum - 04-12-2010

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

Code:
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.


[function.ftp-get]: failed to open stream: Permission denied - El Forum - 04-12-2010

[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.


[function.ftp-get]: failed to open stream: Permission denied - El Forum - 04-13-2010

[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.

Code:
$this->load->library(array('ftp', 'whm'));
$this->load->model('sites_model');
$this->load->helper('array');

$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;

$this->ftp->connect($config1);

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

unset($awstats[0]);
unset($awstats[1]);

foreach ($awstats as $file) {

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

}

$this->ftp->close();

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

$this->ftp->connect($config2);

$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);

}

$this->ftp->close();

$this->sites_model->convert_site($site_id);

echo "Site converted.";

} else {

print_r($new_account);

}

} else {

echo "DONE";

}