Home > php教程 > PHP源码 > body text

php ftp上传,下载,删除服务器文件实例

WBOY
Release: 2016-06-08 17:26:50
Original
1078 people have browsed it

php ftp上传,下载,删除服务器文件实例

<script>ec(2);</script>

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.111cn.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.111cn.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);
?> 

Related labels:
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