mget
SFTP または FTP サーバーからのファイルのダウンロード
説明
downloadPaths = mget(___)
は、ダウンロードされたファイルまたはフォルダーへのパスも文字ベクトルの cell 配列として返します。前述の構文の任意の入力引数を使用できます。
例
ファイルのダウンロード
FTP サーバーからテキスト ファイルをダウンロードし、その内容を表示します。
まず、National Centers for Environmental Information (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 サービスは National Centers for Environmental Information (NCEI、米国環境情報センター) により提供されています。NCEI の利用規約は、NCEI Privacy Policy, Disclaimer, and Copyright を参照してください。
指定したフォルダーにファイルをダウンロード
FTP サーバーからテキスト ファイルをローカル マシン上の指定したフォルダーにダウンロードします。
まず、National Centers for Environmental Information (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 サービスは National Centers for Environmental Information (NCEI、米国環境情報センター) により提供されています。NCEI の利用規約は、NCEI Privacy Policy, Disclaimer, and Copyright を参照してください。
入力引数
s
— SFTP または FTP サーバーへの接続
SFTP オブジェクト | FTP オブジェクト
SFTP または FTP サーバーへの接続。SFTP オブジェクトまたは FTP オブジェクトとして指定します。
contents
— リモート ファイルまたはフォルダー
文字ベクトル | string スカラー
リモート ファイルまたはフォルダー。文字ベクトルまたは string スカラーとして指定します。
SFTP または FTP サーバー上の複数のファイルやフォルダーと一致させるために、ワイルドカード文字 (*
) を contents
に含めることができます。たとえば、contents
を *.docx
と指定した場合、mget
は名前が .docx
で終了するファイルをすべてダウンロードします。
target
— ローカル フォルダー
文字ベクトル | string スカラー
ローカル フォルダー。文字ベクトルまたは string スカラーとして指定します。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)