Welcome Guest, Not a member yet? Register   Sign In
Problems with FTP on linux
#1

[eluser]Maranax[/eluser]
: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.
#2

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

[eluser]Maranax[/eluser]
ranjudsokomora,

thank you for your reply.
Good point.
I've checked my code again for case sensitivity... Well, everything looks fine. The directories on ftp server are lower cased.
I ran the script again and I got some more information. The full error message was:

Quote:<p>Severity: Warning</p>
<p>Message: ftp_nlist(): php_connect_nonb() failed: Operation now in progress (115)</p>
<p>Filename: libraries/Ftp.php</p>
<p>Line Number: 465</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message: Invalid argument supplied for foreach()</p>
<p>Filename: controllers/balin_ftp.php</p>
<p>Line Number: 31</p>
#4

[eluser]ranjudsokomora[/eluser]
Maranax,
Try this:
Code:
$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/');
echo "<pre>";
print_r($list);
echo "</pre><br /><br />";
EXIT;

What result are you given?
#5

[eluser]Maranax[/eluser]
Here we go:


<pre></pre><br /><br />


Means - nothing.
#6

[eluser]ranjudsokomora[/eluser]
Maranax,
Are there any files or directories in your ftp path? You may also want to turn passive on if you are still having problems.
#7

[eluser]Maranax[/eluser]
Yes, there are around 10-15 files.
I tried to change config['passive'], but it's still the same...
#8

[eluser]Maranax[/eluser]
Ok, seems like it doesn't like the path...

I rewrote the code:

Code:
$conn_id = ftp_connect('ftp.smth');

        // login with username and password
        $login_result = ftp_login($conn_id, 'user', 'password');

        // check connection
        if ((!$conn_id) || (!$login_result)) {
            echo "FTP connection has failed!";
            echo "Attempted to connect to $ftp_server for user $ftp_user_name";

            exit;
        } else {
            echo "Connected to ftp, for user user";
            return ftp_nlist($conn_id, "/");    

        }

        ftp_close($conn_id);

So, it connects, but returns nothing.
I'll be investigating... Maybe there is something wrong with php installation.




Theme © iAndrew 2016 - Forum software by © MyBB