Home > php教程 > php手册 > php下连接ftp实现文件的上传、下载、删除文件实例代码

php下连接ftp实现文件的上传、下载、删除文件实例代码

WBOY
Release: 2016-06-13 12:15:27
Original
1252 people have browsed it

php ftp传送文件到服务器

复制代码 代码如下:


// 开始
$ret = ftp_nb_get ($my_connection, "test", "README", FTP_BINARY,
filesize("test"));
// 或: $ret = ftp_nb_get ($my_connection, "test", "README",
// FTP_BINARY, FTP_AUTORESUME);
while ($ret == FTP_MOREDATA) {

// 可以插入其它代码
echo ".";
// 继续传送...
$ret = ftp_nb_continue ($my_connection);
}
if ($ret != FTP_FINISHED) {
echo "下载出错...";
exit(1);
}
?>


php ftp删除文件

复制代码 代码如下:


$file = 'public_html/old.txt';
// 连接FTP服务器
$conn_id = ftp_connect('www.jb51.net');
// 验证用户名和密码
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// 删除指定文件
if (ftp_delete($conn_id, $file)) {
echo "$file 文件删除成功 n";
} else {
echo "删除 $file 文件失败n";
}
// 关闭FTP连接
ftp_close($conn_id);
?>


php ftp下载文件

复制代码 代码如下:


$file = 'somefile.txt';
// 连接FTP服务器
$conn_id = ftp_connect($ftp_server);
//验证用户名和密码www.jb51 .net
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//获取指定文件的大小
$res = ftp_size($conn_id, $file);
if ($res != -1) {
echo " $file 文件大小为 $res字节";
} else {
echo "获取远程文件大小失败";
}
//关闭FTP连接
ftp_close($conn_id);
?>

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template