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);
FTP と FTPS
PHP 4、PHP 5、PHP 6。ftps:// は PHP 4.3.0 以降。
- 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
FTP 経由でのファイルの読み込みと新しいファイルの作成を許可します。 サーバがパッシブモードの FTP をサポートしていない場合、接続は失敗します。
読み込み用または書き込み用のどちらかでファイルをオープンすることが 可能ですが、それらを両方同時に指定することはできません。FTP サーバ上の 既存のファイルを書き込み用にオープンしようとした場合、もし コンテキストオプション overwrite が指定されていなければ 接続は失敗します。既存のファイルを FTP 越しに上書きしたい場合は、 コンテキストオプション overwrite を指定したうえで 書き込み用にファイルをオープンします。別の方法としては、 FTP 拡張モジュール を使用することも可能です。
注意: 追記
PHP 5.0.0 では、ftp:// URL ラッパー経由での ファイルの追記が可能となりました。それ以前のバージョンでは ftp:// 経由でのファイルの追記は失敗していました。
ftps:// は PHP 4.3.0 から有効になりました。 これは ftp:// と同じですが、FTP サーバとの 安全な接続を確立しようと試みます。もしサーバが SSL をサポートして いなければ、通常の(暗号化されない)FTP を使用します。
注意: FTPS のサポートは PHP 4.3.0 から始まりました。これを使用するには OpenSSL サポートを含めて PHP をコンパイルする必要があります。
| 属性 | PHP 4 | PHP 5 |
|---|---|---|
| allow_url_fopen で制約される | Yes | Yes |
| 読み込み許可 | Yes | Yes |
| 書き込み許可 | Yes(新規ファイルのみ) | Yes(新規ファイル あるいは 既存のファイルで overwrite を指定) |
| 追加許可 | No | Yes |
| 同時読み書き許可 | No | No |
| stat() のサポート | No | PHP 5.0.0 では filesize()、 filetype()、file_exists()、 is_file() および is_dir() のみ。 PHP 5.1.0 で filemtime()。 |
| unlink() のサポート | No | Yes |
| rename() のサポート | No | Yes |
| mkdir() のサポート | No | Yes |
| rmdir() のサポート | No | Yes |
FTP と FTPS
25-Apr-2008 01:41
09-Oct-2006 09:32
old fashioned FTP servers may not be compatible with ftp_connect().
<?
$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);
?>
04-Jul-2004 12:39
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
