Main Content

cd

Change or view current folder on SFTP or FTP server

Description

cd(s,folder) changes the current folder on the SFTP or FTP server associated with s.

example

cd(s) displays the path to the current folder on the server.

newFolder = cd(___) also returns the path as a character vector. You can use the input arguments from either of the previous syntaxes. If you use the first syntax, then newFolder is the path after you change the folder.

Examples

collapse all

Open a connection to an SFTP server by creating an SFTP object. List the contents of subfolders on the server using the SFTP object. At the end of the SFTP session, close the connection.

First, connect to the example SFTP server.

s = sftp("sftp.example_galapagos.net","jsmith")
  SFTP with properties:

                         Host: "sftp.example_galapagos.net"
                     Username: "jsmith"
                         Port: 22
                 ServerSystem: "unix"
                 DatetimeType: "datetime"
                 ServerLocale: "en_US"
                 DirParserFcn: @matlab.io.ftp.parseDirListingForUnix
       RemoteWorkingDirectory: "/home/jsmith"

List the contents of the top-level folder.

dir(s)
 
air_quality                  fish                        insects                       README.txt
birds                        INDEX.txt                   mammals                       reptiles
climate                      index.html                  rainfall                      sftp.html
 

List the contents of a subfolder using the dir function.

dir(s,"home/jsmith/birds")
 
albatrosses                 ducks                       herons                     parrots 
avocets_stilts              falcons                     kingfishers                pelicans
barn_owls                   flamingos                   mockingbirds               penguins 
blackbirds                  frigatebirds                nightjars                  pheasants 
boobies                     grebes                      northern_storm_petrels     pigeons 
cardinal grosbeaks          guineafowl                  osprey                     plovers 
cormorants                  gulls                       owls                       rails
cuckoos                     hawks                       oystercatcher              sandpipers
 

Change to a subfolder using the cd function. The output from cd is the path to the current folder on the SFTP server, not your current MATLAB folder.

cd(s,"home/jsmith/birds/herons")
ans = 
"home/jsmith/birds/herons"

List the contents of the current folder.

dir(s)
documentation             great_egret_data              migration_patterns
great_blue_heron_data     green_heron_data              nesting_behaviors 

Close the connection to the SFTP server. You also can close the connection by deleting the SFTP object or letting the connection time out.

close(s)

Input Arguments

collapse all

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

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

Tips

  • Pass the ~ symbol to the cd function to navigate to the login folder.

Version History

Introduced before R2006a

See Also

| |

Go to top of page