ftp://

ftps://

ftp:// -- ftps://FTP(s) URL へのアクセス

説明

FTP 経由でのファイルの読み込みと新しいファイルの作成を許可します。 サーバーがパッシブモードの FTP をサポートしていない場合、接続は失敗します。

読み込み用または書き込み用のどちらかでファイルをオープンすることが 可能ですが、それらを両方同時に指定することはできません。FTP サーバー上の 既存のファイルを書き込み用にオープンしようとした場合、もし コンテキストオプション overwrite が指定されていなければ 接続は失敗します。既存のファイルを FTP 越しに上書きしたい場合は、 コンテキストオプション overwrite を指定したうえで 書き込み用にファイルをオープンします。別の方法としては、 FTP 拡張モジュール を使用することも可能です。

from ディレクティブを php.ini で設定した場合、この値が anonymous FTP のパスワードとして送信されます。

利用法

  • ftp://example.com/pub/file.txt
  • ftp://user:password@example.com/pub/file.txt
  • ftps://example.com/pub/file.txt
  • ftps://user:password@example.com/pub/file.txt

オプション

ラッパーの概要
属性 サポート対象か
allow_url_fopen で制約される Yes
読み込み許可 Yes
書き込み許可 Yes(新規ファイル あるいは 既存のファイルで overwrite を指定)
追加許可 Yes
同時読み書き許可 No
stat() のサポート filesize()filemtime()filetype()file_exists()is_file()is_dir() のみ。
unlink() のサポート Yes
rename() のサポート Yes
mkdir() のサポート Yes
rmdir() のサポート Yes

注意

注意:

FTPS がサポートされるのは、openssl 拡張モジュールが有効な場合のみです。

もしサーバーが SSL をサポートして いなければ、通常の(暗号化されない)FTP を使用します。

注意: 追記
ftp:// URL ラッパー経由での ファイルの追記が可能です。

add a note add a note

User Contributed Notes 3 notes

up
-1
php at f00n dot com
19 years ago
For Intranet purposes I found I preferred to move my file via ftp functions to match the session user's ftp account and put the file in a holding bay so I knew who it was from.

The FTP wrapper method will NOT do this if your ftp server does NOT support passive mode.

eg.  an ftp server behind NAT/routing
up
-10
Anonymous
18 years ago
<?
$str ="replace all contenents";
$filew="ftp://gufo:gufo@192.168.1.55:21/jj.php";
$opts = array('ftp' => array('overwrite' => true));
$context = stream_context_create($opts);
$strwri = file_put_contents($filew,$str,LOCK_EX,$context);
?>
up
-14
fazil dot stormhammer dot nospam at gmail dot com
15 years ago
Document says "Allows read access to existing files and creation of new files via FTP. If the server does not support passive mode ftp, the connection will fail. "

As of version 5.2.5 at least fopen("ftp://...") uses an ACTIVE mode connection by default (it issues an FTP PORT command but not a PASV command).  To force passive mode:

$f = fopen("ftp://...");
ftp_pasv($f, true);
To Top