CodeIgniter Forums
Please help! This is urgent!! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Please help! This is urgent!! (/thread-11685.html)



Please help! This is urgent!! - El Forum - 09-19-2008

[eluser]Gewa[/eluser]
Hi,
i am making a code which is supposed to

a)take ftp account datas of our bought domains from the database
b) login with that data
c) find /public_html or /www folder
d) upload a index.php


but I get error... What is the problem? Can you help to fix?


Code:
function do_spam($limit,$offset){


      
        $query=$this->db->get_where('ftp_list',array('status'=>'0'),$limit,$offset);




                $redirect_link=$this->input->post('link');



                // open file for reading
                    $file = './uploads/index.php';
                          $fp = fopen($file, 'w');

               $file_content='<?

echo"<meta http-equiv=\"refresh\" content=\"0;url='.$redirect_link.'\">";
?>';
                fwrite($fp,$file_content);


          if($query->num_rows()>0){




              foreach($query->result() as $list){

              $ftp_server=$list->host;
              $ftp_user_name=$list->login;
              $ftp_user_pass=$list->pass;
              $id=$list->id;
              // установка соединения
                     $conn_id = @ftp_connect($ftp_server,21,20);

                  if($conn_id){
                         // вход с именем пользователя и паролем
                       $login_result = @ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

                             if ($login_result) {



                                   //searching and entering v /www ili /public_html
                              $now_dir=ftp_pwd($conn_id);
                              if($now_dir!="/public_html" or $now_dir!="/www"){
                                $change= @ftp_chdir($conn_id, "public_html");

                                if($change!=TRUE){

                                  $change= @ftp_chdir($conn_id, "www");


                                }







                                  }



                            if($change){



                             if (ftp_fput($conn_id, 'index.php', $fp, FTP_ASCII)) {


                                         $update = array(
                                                  'status' => '1',
                                                   'error'=>'File Uploaded'
                                                    );

                                              $this->db->where('id', $id);
                                              $this->db->update('ftp_list', $update);





                                      }


                                       else {

                                         $update = array(
                                                  'status' => '2',
                                                   'error'=>'File not uploaded'
                                                    );

                                              $this->db->where('id', $id);
                                              $this->db->update('ftp_list', $update);






                                      }

                               // close the connection and the file handler
                                      ftp_close($conn_id);
                                      fclose($fp);






                           }
                            else{

                                                                 $update = array(
                                                  'status' => '2',
                                                   'error'=>'Не могу найти директорию www или public_html'
                                                    );

                                              $this->db->where('id', $id);
                                              $this->db->update('ftp_list', $update);


                            }



                     }


              else {


                                                             $update = array(
                                                  'status' => '2',
                                                   'error'=>'Incorect login and password'
                                                    );

                                              $this->db->where('id', $id);
                                              $this->db->update('ftp_list', $update);




                    }    
             }
             else{

                                                      $update = array(
                                                  'status' => '2',
                                                   'error'=>'host connect error'
                                                    );

                                              $this->db->where('id', $id);
                                              $this->db->update('ftp_list', $update);



            }







           }


               $new_offset=$offset+$limit;

                                redirect("/admin/ftp/do_spam/$limit/$new_offset",'refresh');


        }

else{

echo "Process Finished":
}


Host connections are ok, but loop is not working, and error in database is File is not uploaded.. What to do?


Please help! This is urgent!! - El Forum - 09-19-2008

[eluser]Phil Sturgeon[/eluser]
Output various path variables and make sure you have the slashes in the right place.

Does pwd not return a full path?

I have a lot of problems with FTP code and it always boils down to slashes in the wrong place or bad assumptions about root directory or paths.