[eluser]ranjudsokomora[/eluser]
[quote author="Maranax" date="1274909312"]:gulp:
Hi guys!
I use CI as command string. The code is:
Code:
function run_ftp()
{
$config['hostname'] = 'ftp.something';
$config['username'] = 'username';
$config['password'] = 'password';
$config['port'] = '21';
$config['passive'] = FALSE;
$config['debug'] = TRUE;
$this->load->library('ftp');
$this->ftp->connect($config);
$list = $this->ftp->list_files('/data/folder/');
$i = 1;
$file_need = '';
foreach($list as $file)
{
if(substr($file, -3) == '.gz')
{
$file_date = substr($file, -9, 6);
if($file_date > $this->file_date_sample)
{
$file_need = $file;
}
}
$i += 1;
}
echo $file_need;
$this->ftp->close();
}
So, this code works perfectly on Windows machine. But if I run it on Linux box it returns the error message:
Quote:<p>Severity: Warning</p>
<p>Message: Invalid argument supplied for foreach()</p>
<p>Filename: controllers/balin_ftp.php</p>
<p>Line Number: 31</p>
Line 31 is "foreach($list as $file)"
I assume that $list is not an array. But why?
Any help is appreciated.[/quote]
Maranax,
Keep in mind Linux is case sensitive. So if your folder is /Data instead of /data your script will fail. I am unsure of this but I believe by quickly looking at your script that if the FTP directory contains no files or directories your script may fail out.