Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

dir

List folder contents on FTP server

Syntax

dir(ftpobj)
dir(ftpobj,folder)
listing = dir(___)

Description

example

dir(ftpobj) lists the contents of the current folder on the FTP server associated with ftpobj. The contents of the current folder can be files and other folders.

example

dir(ftpobj,folder) lists the contents of the specified folder.

example

listing = dir(___) returns a structure array that contains the name, modification date, and size of each item. You can use this syntax with the input arguments of either of the previous syntaxes.

Examples

collapse all

List the contents of a folder and a subfolder on an FTP server.

First, connect to the National Centers for Environmental Information (NCEI) FTP server.

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

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

List the contents of the current folder on the server. At the start of a session, the current folder is the highest level folder to which you have access.

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

Specify a subfolder and list its contents.

dir(ftpobj,'pub')
 
WebCD     coast     glac_lib  krm       outgoing  results   rgon                          
 

FTP service courtesy of the National Centers for Environmental Information (NCEI). See the NCEI Privacy Policy, Disclaimer, and Copyright for NCEI terms of service.

List details of the contents on an FTP server. The dir function can return a structure array that contains the name, modification date, and size of each item in the specified folder.

First, connect to the National Centers for Environmental Information (NCEI) FTP server.

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

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

Return details about the items in the top-level folder on the FTP server. Some items are files and the others are folders.

listing = dir(ftpobj)
listing = 19×1 struct array with fields:
    name
    bytes
    isdir
    date
    datenum

Display details about the first item in the current folder, which is a folder named DSMP.

listing(1)
ans = struct with fields:
       name: 'DMSP'
      bytes: 32
      isdir: 1
       date: '10-Sep-2012 00:00:00'
    datenum: 735122

FTP service courtesy of the National Centers for Environmental Information (NCEI). See the NCEI Privacy Policy, Disclaimer, and Copyright for NCEI terms of service.

Input Arguments

collapse all

Connection to an FTP server, specified as an FTP object.

Name of the target folder on the FTP server, specified as a character vector or string scalar. To specify the folder above the current one, use '..'.

Output Arguments

collapse all

Content attributes, returned as an m-by-1 structure array, where m is the number of items in the folder.

This table shows the fields in the structure.

Field NameDescriptionData Type
name

File or folder name

char

bytes

Size of the item in bytes

double

isdir

1 if name is a folder; 0 if name is a file

logical

date

Modification date timestamp

char

datenum

Modification date as serial date number (for more information, see datenum)

double

Tips

  • The dir function might return a structure array in which the last four fields are empty or missing. When dir returns a structure with missing information, it might mean the FTP object is not configured for the operating system that is running on the FTP server. By default, an FTP object is configured to connect to a server running a UNIX® operating system.

    To configure an FTP object for a connection to a server running Windows®, call the ftp function and specify the 'System','WINDOWS' name-value pair. Then call dir using the new FTP object.

See Also

| | |

Introduced before R2006a

Was this topic helpful?