ftp://
ftps://
ftp:// -- ftps:// — 访问 FTP(s) URLs
说明
允许通过 FTP 读取存在的文件,以及创建新文件。 如果服务器不支持被动(passive)模式的 FTP,连接会失败。
打开文件后你既可以读也可以写,但是不能同时进行。
当远程文件已经存在于 ftp 服务器上,如果尝试打开并写入文件的时候,
未指定上下文(context)选项 overwrite
,连接会失败。
如果要通过 FTP 覆盖存在的文件,
指定上下文(context)的 overwrite
选项来打开、写入。
另外可使用 FTP 扩展来代替。
如果你设置了 php.ini 中的 from 指令, 这个值会作为匿名(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
注释
注意:
FTPS 仅在 openssl 扩展开启时有效。
如果服务器不支持 SSL,这个连接会降级(falls back)到普通未加密的 ftp。
注意: 追加
文件可以通过ftp://
URL 封装器来追加(append)。
参见

User Contributed Notes 3 notes
php at f00n dot com ¶
17 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
Anonymous ¶
16 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);
?>
fazil dot stormhammer dot nospam at gmail dot com ¶
14 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);