php How to delete files through ftp: first connect to ftp; then download the file through the "ftp_get" function; then use the "ftp_delete($con,"eee.doc");" method to directly delete the file.
Recommended: "PHP Video Tutorial"
php operation ftp upload files, create directories, delete files, delete Directory, download files to the local
<?php $host = 'xxx'; $user = 'user'; $pwd = '123'; $con = ftp_connect($host); $login = ftp_login($con,$user,$pwd); if($login){ echo "ftp链接成功!<br/>"; } $file1="baaa.doc"; echo ftp_put($con,$file1,"2222/aaa.doc",FTP_BINARY);//file1shi ftp的路径 第二个参数是当前服务器上的路径 2222/aaa.doc是本地的路径 echo "<br>"; $file2="测试aaa.doc"; //中文也是好使的 echo ftp_put($con,$file2,"2222/测试.doc",FTP_BINARY);//file1shi ftp的路径 第二个参数是当前服务器上的路径 2222/aaa.doc是本地的路径 echo "<br>"; $path="444/555";//创建目录只能一层一层的创建 $dir=explode("/", $path); $path=""; for ($i=0;$i<count($dir);$i++) { $path.="/".$dir[$i]; echo $path."<br>"; if(!@ftp_chdir($con,$path)){ @ftp_chdir($con,"/"); if(!@ftp_mkdir($con,$path)){ $ret=false; break; } } } ftp_put($con,"eee.doc","2222/aaa.doc",FTP_BINARY);//file1shi ftp的路径 第二个参数是当前服务器上的路径 此时放到了555下面 // echo ftp_pwd($con)."<br>";//当前目录名 //exit; @ftp_chdir($con,"../"); ftp_put($con,$file1,"2222/aaa.doc",FTP_BINARY); //附件放到了444里面 FTP_ASCII //把当前目录切换为父目录 ftp_cdup($con); //回到了上一级目录 默认的是share下 ftp_put($con,"ccc.doc","2222/aaa.doc",FTP_BINARY); //附件放到了444里面 @ftp_chdir($con,"444"); //进入到了444目录 //文件下载 ftp_get($con,"2222/aaa1.doc", "baaa.doc", FTP_BINARY);//第一个是本地 第二个是ftp的路径文件 @ftp_chdir($con,"555");//进入555 ftp_delete($con,"eee.doc"); //删除文件是好使的 ftp_cdup($con); ftp_rmdir($con,"555"); //删除目录 echo ftp_pwd($con)."<br>";//当前目录名 //http://www.w3school.com.cn/php/php_ref_ftp.asp ftp_close($con); ?> </body> </html>
ftp is not very efficient, it is recommended to use curl
function file_upload($ftpIp,$ftpUser,$ftpPwd,$path,$fileSavePath){ $curlobj = curl_init();//初始化 //传入ftp的目标文件,如'ftp://192.168.3.1/test/1.jpg' curl_setopt($curlobj,CURLOPT_URL,"ftp://".$ftpIp."/".$path); curl_setopt($curlobj,CURLOPT_HEADER,0);//不输出header curl_setopt($curlobj,CURLOPT_RETURNTRANSFER,0); //time out after 300s curl_setopt($curlobj,CURLOPT_TIMEOUT,2000);//超时时间 //通过这个函数设置ftp的用户名和密码,没设置就不需要! curl_setopt($curlobj,CURLOPT_USERPWD,$ftpUser.':'.$ftpPwd); $outfile = fopen($fileSavePath,'w+'); //保存到本地文件的文件名 curl_setopt($curlobj,CURLOPT_FILE,$outfile); $rtn = curl_exec($curlobj); if(curl_errno($curlobj)){ writeLog('Curl error: ' . curl_error($curlobj)); } fclose($outfile); curl_close($curlobj); if($rtn == 1){ return true; }else{ unlink($fileSavePath);//如果下载失败,但是本地open了这个文件,所以要删除 return false; } }
The above is the detailed content of How to delete files in php ftp. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment