2011-10-14 3 views
0

Codeigniter를 사용하여 웹 사이트를 만들고 FTP를 통해 원격 호스트에 전체 디렉토리를 업로드하는 기능을 만들려고했지만 아무 것도 작동하지 않습니다.PHP를 통해 PHP를 통해 FTP를 통해 원격 호스트에 업로드

나는 내가 찾은이 개 기능을 시도뿐만 아니라, 작동하지 않는, 단지 몇 개의 파일 업로드 및 일부 파일 크기가 0 바이트 사용

기능입니다 :

// 1St Function 

public function ftp_copy($src_dir, $dst_dir) { 
     $d = dir($src_dir); 

     while($file = $d->read()) { 

      if ($file != "." && $file != "..") { 

       if (is_dir($src_dir."/".$file)) { 

        if ([email protected]_chdir($this->conn_id, $dst_dir."/".$file)) { 

         ftp_mkdir($this->conn_id, $dst_dir."/".$file); 
        } 

        ftp_copy($src_dir."/".$file, $dst_dir."/".$file); 
       } 
       else { 

        $upload = ftp_put($this->conn_id, $dst_dir."/".$file, $src_dir."/".$file, FTP_BINARY); 
       } 
      } 
     } 

     $d->close(); 
    } 


// 2nd Solution from Stackoverflow question 
    foreach (glob("/directory/to/upload/*.*") as $filename) 
     ftp_put($ftp_stream, basename($filename) , $filename, FTP_BINARY); 

모든 솔루션?

+1

사용하고있는 기능은 무엇인가? – Ben

+0

함수를 추가했습니다. – Hamza

답변

4

codeigniter를 사용하는 경우 FTP 라이브러리에서 $ this-> ftp-> mirror()를 사용할 수 있습니다.

http://codeigniter.com/user_guide/libraries/ftp.html

$this->load->library('ftp'); 

$config['hostname'] = 'ftp.example.com'; 
$config['username'] = 'your-username'; 
$config['password'] = 'your-password'; 
$config['debug'] = TRUE; 

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

$this->ftp->mirror('/path/to/myfolder/', '/public_html/myfolder/'); 

$this->ftp->close(); 
+0

미러 기능을 사용하고 있었지만 소스 디렉토리를 후행 슬래시없이 전달했습니다. 이제 후행 슬래시가 추가되어 작동합니다. 감사합니다. – Hamza

+0

프레임 워크의 유용성이 다시 나타납니다. – Xeoncross