Posted
Filed under Linux

FTP함수의  종류와  사용법 

(1)  ftp_connect  :  FTP서버에  연결한다. 
----------------------------------------------- 
int  ftp_connect  (string  host  [,  int  port]) 
$ftp=ftp_connect("서버주소  또는  도메인명",21); 
----------------------------------------------- 

(2)  ftp_login  :  계정과  패스워드로  서버에  접근한다. 
----------------------------------------------- 
int  ftp_login  (int  ftp_stream,  string  username,  string  password) 
$ftplogin  =  ftp_login($ftp,  "$ftp_user_name",  "$ftp_user_pass"); 
----------------------------------------------- 

(3)  ftp_pwd  :  현재  디렉토리  값을  리턴한다. 
----------------------------------------------- 
int  ftp_pwd  (int  ftp_stream) 
$ftp_dir  =  $ftp_pwd($ftp); 
----------------------------------------------- 

(4)  ftp_cdup  :  가장  상위  디렉토리로  이동 
----------------------------------------------- 
int  ftp_cdup  (int  ftp_stream) 
$ftp_dir  =  $ftp_cdup($ftp); 
----------------------------------------------- 

(5)  ftp_chdir  :  FTP  디렉토리의  변경 
----------------------------------------------- 
int  ftp_chdir  (int  ftp_stream,  string  directory) 
$chdir=ftp_chdir  ($ftp,  $ftp_dir); 
----------------------------------------------- 

(6)  ftp_mkdir  :  디렉토리를  만들고  만든  디렉토리명을  반환한다. 
----------------------------------------------- 
string  ftp_mkdir  (int  ftp_stream,  string  directory) 
$mkdir  =  ($ftp,"만들  디렉토리명"); 
----------------------------------------------- 

(7)  ftp_rmdir  :  디렉토리를  삭제한다. 
----------------------------------------------- 
int  ftp_rmdir  (int  ftp_stream,  string  directory) 
$mkdir  =  ($ftp,"삭제할  디렉토리명"); 
----------------------------------------------- 

(8)  ftp_nlist  :  디렉토리의  파일이름을  배열로  반환한다. 
----------------------------------------------- 
int  ftp_nlist  (int  ftp_stream,  string  directory) 
$contents  =  ftp_nlist(  $ftp,  "디렉토리명"); 
----------------------------------------------- 

(9)  ftp_rawlist  :  디렉토리의  파일이름과  읽고  쓰고  실행할  권한을  파일  당  한  줄의  배열로  반환한다. 
----------------------------------------------- 
int  ftp_rawlist  (int  ftp_stream,  string  directory) 
$contents  =  ftp_nlist(  $ftp,  "디렉토리명"); 
----------------------------------------------- 

(10)  ftp_systype  :  FTP서버의  타입을  리턴하는데  리눅스는  UNIX로  표시해준다. 
----------------------------------------------- 
int  ftp_systype  (int  ftp_stream) 
echo  ftp_systype($ftp); 
----------------------------------------------- 

(11)  ftp_get  :  FTP로부터  파일을  다운로드  받는다. 
----------------------------------------------- 
int  ftp_get  (int  ftp_stream,  string  local_file,  string  remote_file,  int  mode) 
$download  =  ftp_get($ftp,  "저장할  파일명",  "다운받을  파일명","FTP_ASCII  or  FTP_BINARY"); 
----------------------------------------------- 

.pl  또는  .cgi  같은  Perl  CGI인  경우에는  FTP_ASCII로  다운  받고  다른  파일은  FTP_BINARY로  다운  받아야  한다. 

(12)  ftp_fget  :  FTP로부터  파일  포인터를  다운받는다. 
----------------------------------------------- 
int  ftp_fget  (int  ftp_stream,  int  fp,  string  remote_file,  int  mode) 
$download  =  ftp_fget($ftp,  "저장할  파일명",  "다운받을  파일명","FTP_ASCII  or  FTP_BINARY"); 
----------------------------------------------- 

(13)  ftp_put  :  FTP서버에  파일을  업로드  한다. 
----------------------------------------------- 
int  ftp_put  (int  ftp_stream,  string  remote_file,  string  local_file,  int  mode) 
$upload  =  ftp_put($ftp,  "업로드할  파일명",  "업로드될  파일명","FTP_ASCII  or  FTP_BINARY"); 
----------------------------------------------- 

(14)  ftp_fput  :  FTP서버에  파일  포인터를  업로드한다. 
----------------------------------------------- 
int  ftp_fput  (int  ftp_stream,  string  remote_file,  string  local_file,  int  mode) 
$upload  =  ftp_fput($ftp,  "업로드할  파일명",  "업로드될  파일명","FTP_ASCII  or  FTP_BINARY"); 
----------------------------------------------- 

(15)  ftp_size  :  파일의  사이즈를  구한다. 
----------------------------------------------- 
int  ftp_size  (int  ftp_stream,  string  remote_file) 
$filesize  =  ftp_size(  $ftp,  $contents[$i]  ); 
----------------------------------------------- 
ftp_nlist  나  ftp_rawlist에  의해  구한  파일명에  대한  배열값인  $contents[$i]에는  각  파일명과  속성이  저장되어지는데  이  파일명을  사이즈로  구하면  파일이면  사이즈가  리턴되고  디렉토리이면  -1이  리턴된다. 

(16)  ftp_mdtm  :  파일의  마지막  수정시간을  timestamp  값으로  리턴한다. 
----------------------------------------------- 
int  ftp_mdtm  (int  ftp_stream,  string  remote_file) 
$filemdth  =  ftp_size(  $ftp,  "파읾명"); 
----------------------------------------------- 

(17)  ftp_rename  :  파일명을  변경한다. 
----------------------------------------------- 
int  ftp_rename  (int  ftp_stream,  string  from,  string  to) 
$rename  =  ftp_rename(  $ftp,  "바꿀  파일명",  "바뀐  후  파일명"); 
----------------------------------------------- 

(18)  ftp_delete  :  해당  파일을  삭제한다. 
----------------------------------------------- 
int  ftp_delete  (int  ftp_stream,  string  path) 
$delfile  =  ftp_delete($ftp,  "지울  파일명"); 
----------------------------------------------- 

(19)  ftp_quit  :  연결된  FTP의  접속을  끊는다. 
----------------------------------------------- 
int  ftp_quit  (int  ftp_stream) 
ftp_quit  ($ftp); 
-----------------------------------------------  

2009/07/17 20:34 2009/07/17 20:34