array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'ftp.examples-basic.php', 1 => '基本用法', ), 'up' => array ( 0 => 'ftp.examples.php', 1 => '示例', ), 'prev' => array ( 0 => 'ftp.examples.php', 1 => '示例', ), 'next' => array ( 0 => 'ref.ftp.php', 1 => 'FTP 函数', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/ftp/examples.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
示例 #1 FTP 示例
<?php
// 建立基础连接
$ftp = ftp_connect($ftp_server);
// 使用用户名和口令登录
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);
// 检查是否成功
if ((!$ftp) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// 上传文件
$upload = ftp_put($ftp, $destination_file, $source_file, FTP_BINARY);
// 检查上传结果
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// 关闭 FTP 连接
ftp_close($ftp);
?>