ftp_fget
(PHP 3 >= 3.0.13, PHP 4, PHP 5)
ftp_fget -- FTP サーバからファイルをダウンロードし、オープン中のファイルに保存する
説明
bool
ftp_fget ( resource ftp_stream, resource handle, string remote_file, int mode [, int resumepos] )
ftp_fget() は、FTP サーバから
remote_file を取得し、指定したファイルポインタ
fp に書きこみます。
パラメータ
- ftp_stream
FTP 接続のリンク ID 。
- handle
オープンされているファイルのポインタ。ここにデータが保存されます。
- remote_file
リモートファイルのパス。
- mode
転送モード。FTP_ASCII または
FTP_BINARY のどちらかを指定する必要があります。
- resumepos
リモートファイル中で、ダウンロードを開始する位置。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
例
例 1. ftp_fget() の例
<?php
// 読み込むファイルをオープンする $remote_file = 'somefile.txt'; $handle = fopen('localfile.txt', 'w');
// 接続を確立する $conn_id = ftp_connect($ftp_server);
// ユーザ名とパスワードでログインする $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// $file のダウンロードを試みる if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) { echo "successfully written to $file\n"; } else { echo "There was a problem with $file\n"; }
// 接続を閉じ、ファイルを閉じる ftp_close($conn_id); fclose($handle); ?>
|
|