mget
从 SFTP 或 FTP 服务器下载文件
说明
示例
下载文件
从 FTP 服务器上下载文本文件并显示其内容。
首先,连接到美国国家环境信息中心 (NCEI) 的 FTP 服务器。
s = ftp('ftp.ngdc.noaa.gov')
FTP with properties: Host: "ftp.ngdc.noaa.gov" Username: "anonymous" Port: 21 ServerLocale: "en_US" DirParserFcn: @matlab.io.ftp.parseDirListingForUnix Mode: "binary" LocalDataConnectionMethod: "passive" RemoteWorkingDirectory: "/"
下载文本文件。mget
函数将文件下载到您计算机上的当前文件夹中。
mget(s,'README.txt');
显示 README.txt
的开头。要读取下载到您计算机上的 README.txt
副本,请使用 fileread
函数。
readme = fileread('README.txt');
readme(1:95)
ans = ' Welcome to the NOAA/National Centers for Environmental Information (NCEI)'
FTP 服务由美国国家环境信息中心 (NCEI) 提供。有关 NCEI 服务条款,请参阅 NCEI 隐私政策、免责声明和版权。
将文件下载到指定文件夹中
将文本文件从 FTP 服务器下载到您本地计算机上的指定文件夹中。
首先,连接到美国国家环境信息中心 (NCEI) 的 FTP 服务器。
s = ftp('ftp.ngdc.noaa.gov')
FTP with properties: Host: "ftp.ngdc.noaa.gov" Username: "anonymous" Port: 21 ServerLocale: "en_US" DirParserFcn: @matlab.io.ftp.parseDirListingForUnix Mode: "binary" LocalDataConnectionMethod: "passive" RemoteWorkingDirectory: "/"
将文本文件下载到名为 myLocalFolder
的文件夹中。如果此文件夹不存在,mget
函数会在您的本地计算机上创建一个文件夹。
mget(s,'README.txt','myLocalFolder');
使用 fileread
函数读取 README.txt
的开头部分。
readme = fileread('myLocalFolder/README.txt');
readme(1:95)
ans = ' Welcome to the NOAA/National Centers for Environmental Information (NCEI)'
FTP 服务由美国国家环境信息中心 (NCEI) 提供。有关 NCEI 服务条款,请参阅 NCEI 隐私政策、免责声明和版权。
输入参数
s
— 连接到 SFTP 或 FTP 服务器
SFTP 对象 | FTP 对象
与 SFTP 或 FTP 服务器的连接,指定为 SFTP 对象或 FTP 对象。
contents
— 远程文件或文件夹
字符向量 | 字符串标量
远程文件或文件夹,指定为字符向量或字符串标量。
要匹配 SFTP 或 FTP 服务器上的多个文件或文件夹,可以在 contents
中包含一个通配符 (*
)。例如,如果您将 contents
指定为 *.docx
,则 mget
会下载名称以 .docx
结尾的所有文件。
target
— 本地文件夹
字符向量 | 字符串标量
本地文件夹,指定为字符向量或字符串标量。target
可以指定相对路径或绝对路径。
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)