Main Content

cd

更改或查看 SFTP 或 FTP 服务器上的当前文件夹

说明

示例

cd(s,folder) 更改与 s 关联的 SFTP 或 FTP 服务器上的当前文件夹。

cd(s) 显示服务器上当前文件夹的路径。

newFolder = cd(___) 还以字符向量形式返回路径。您可以使用前面任一语法中的输入参量。如果您使用第一种语法,则 newFolder 是更改文件夹后的路径。

示例

全部折叠

通过创建 SFTP 对象打开与 SFTP 服务器的连接。使用 SFTP 对象列出服务器上子文件夹的内容。在 SFTP 会话结束后,关闭连接。

首先,连接到示例 SFTP 服务器。

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"

列出顶层文件夹的内容。

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

使用 dir 函数列出子文件夹的内容。

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
 

使用 cd 函数切换到子文件夹。cd 的输出是 SFTP 服务器上当前文件夹的路径,而不是当前 MATLAB 文件夹的路径。

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

列出当前文件夹的内容。

dir(s)
documentation             great_egret_data              migration_patterns
great_blue_heron_data     green_heron_data              nesting_behaviors 

关闭与 SFTP 服务器的连接。您也可以通过删除 SFTP 对象或让连接超时来关闭连接。

close(s)

输入参数

全部折叠

与 SFTP 或 FTP 服务器的连接,指定为 SFTP 对象或 FTP 对象。

SFTP 或 FTP 服务器上的目标文件夹的名称,指定为字符向量或字符串标量。要指定当前文件夹的上一级文件夹,请使用 '..'

提示

  • ~ 符号传递给 cd 函数以导航到登录文件夹。

版本历史记录

在 R2006a 之前推出

另请参阅

| |