PHP 中如何连接FTP,知道文件名,删除其中的文件
发布网友
发布时间:2022-04-23 09:46
我来回答
共2个回答
热心网友
时间:2022-04-06 05:30
<?php
// set up basic connection
$ftp_server = '10.3.23.254';
$conn_id = ftp_connect($ftp_server);
// login with username and password
$ftp_user_name = 'admin';
$ftp_user_pass = 'xuu9898';
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$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";
}
// delete the file
$destination_file = '/backup/m37/abc.txt';
$deleted= ftp_delete($conn_id, $destination_file);
// check deleted status
if (!$deleted) {
echo "FTP delete has failed!";
} else {
echo "delete $destination_file success." }
// close the FTP stream
ftp_close($conn_id);
?>
===========
建议查询手册.
目标服务器必须启动ftp服务.
热心网友
时间:2022-04-06 06:48
tp工具我们都用过是用来上传文件的,那么在php中如何用代码实现呢,下面简单介绍一个最基础最简单的列子,首先根据我们使用ftp工具来说,实现文件上传需要打开ftp工具->输入ftp地址,端口号,账号,密码登陆ftp->从本地选择相应文件上传到ftp相应目录,php中要实现这么一个简单的功能无非也是这样。
第一步:打开ftp
$ip="101.101.101.101";
$name="name";
$pwd="mima";
$con=ftp_connect($ip,"21") or("连接失败");
参考资料
http://www.itnet.org.cn/news419.html