Main Content

FTP 파일 작업 수행하기

이 예제에서는 FTP 객체를 사용하여 FTP 서버에 연결한 다음 원격 파일 작업을 수행하는 방법을 보여줍니다. FTP 서버에서 파일 작업을 수행하려면 다음 단계를 따르십시오.

  1. ftp 함수를 사용하여 서버에 연결합니다.

  2. cd, dir, mget 함수 같은 적절한 MATLAB® FTP 함수를 사용하여 작업을 수행합니다. 모든 작업에 대해 FTP 객체를 지정합니다.

  3. 서버에서 작업이 끝나면 close 함수를 사용하여 연결을 닫습니다.

NCEI(National Centers for Environmental Information)는 지구 물리 데이터에 대한 퍼블릭 액세스를 제공하는 익명 FTP 서비스의 관리 기관입니다. FTP 서버에 액세스하여 서버의 내용을 나열하고 파일을 다운로드하고 하위 폴더의 내용을 나열합니다.

먼저, 연결을 엽니다.

ftpobj = ftp('ftp.ngdc.noaa.gov')
ftpobj = 

  FTP Object
     host: ftp.ngdc.noaa.gov
     user: anonymous
      dir: /
     mode: binary

FTP 서버의 최상위 폴더 내용을 나열합니다.

dir(ftpobj)
 
DMSP                         Solid_Earth                  google12c4c939d7b90761.html  mgg                          
INDEX.txt                    coastwatch                   hazards                      pub                          
README.txt                   dmsp4alan                    index.html                   tmp                          
STP                          ftp.html                     international                wdc                          
Snow_Ice                     geomag                       ionosonde                                                 
 

mget 함수를 사용하여 INDEX.txt라는 파일을 다운로드합니다. mget가 로컬 컴퓨터의 현재 MATLAB 폴더에 파일을 복사합니다. 파일 복사본의 내용을 보려면 type 함수를 사용합니다.

mget(ftpobj,'INDEX.txt');
type INDEX.txt
                    National Centers for Environmental Information (NCEI), 
                    formerly the National Geophysical Data Center (NGDC)

                          INDEX of anonymous ftp area
                               ftp.ngdc.noaa.gov

DIRECTORY/FILE DESCRIPTION OF CONTENTS
-------------- -----------------------------------------------------------------
pub/           Public access area 
DMSP/          Defense Meteorological Satellite Data Archive
geomag/        Geomagnetism and geomagnetics models
hazards/       Natural Hazards data, volcanoes, tsunamis, earthquakes
international/ International program information on IAGA/Oersted/wdc
ionosonde/     Ionosonde data
mgg/           Limited Marine Geology and Geophysics (most data in http area)
OD/            Office of the Director
Snow_Ice/      Snow and Ice Data Center
Solid_Earth/   Historic Solid Earth Geophysics
STP/           Solar-Terrestrial Physics
tmp/           Pickup area for temporary outgoing data
wdc/           World Data Service for Geophysics, formerly World Data Centers
-------------- -----------------------------------------------------------------
Please see file README.txt in this directory for more information and how to 
contact NCEI. Direct E-mail inquiries to ncei.info@noaa.gov

Also see our web site: http://www.ngdc.noaa.gov/

NCEI is part of the:
U.S. Department of Commerce, National Oceanic and Atmospheric Administration (NOAA),
National Environmental Satellite, Data and Information Service (NESDIS)

FTP 서버에서 pub라는 하위 폴더로 변경합니다.

cd(ftpobj,'pub')
ans = 
'/pub'

내용을 나열합니다. 이제 pub가 FTP 서버의 현재 폴더입니다. 그러나 로컬 컴퓨터의 현재 MATLAB 폴더는 변경되지 않았습니다. cd, dir 같은 함수를 사용하여 FTP 객체를 지정하는 경우 작업은 로컬 컴퓨터가 아닌 FTP 서버에서 수행됩니다.

dir(ftpobj)
 
WebCD     coast     glac_lib  krm       outgoing  results   rgon                                                                  
 

FTP 서버에 대한 연결을 닫습니다.

close(ftpobj)

NCEI가 공개한 FTP 서비스. NCEI 서비스 약관은 NCEI Privacy Policy, Disclaimer, and Copyright를 참조하십시오.

참고 항목

| | | |

관련 항목