Above I have introduced the use of FTP upload and download, next to share with you is to delete the files on the FTP server section. With the upload, with the download, then delete the nature is also not less.
Delete is easier than uploading and downloading, it does not need to transfer files, just send a delete command to the FTP server.
The following is a complete example of a delete feature:
/// <summary> ///FTP Delete Files/// </summary> /// <param name= "Ftppath" >ftp file path</param> /// <param name= "UserId" >FTP user name</param> /// <param name= "pwd" >ftp Password</param> /// <param name= "FileName" >FTP file name</param> /// <returns></returns> Public stringDeleteFile (stringFtppath,stringUseridstringPwdstringfileName) { stringSret ="Delete Success! "; FtpWebResponse respose=NULL; FtpWebRequest reqftp=NULL; Stream LocalFile=NULL; Stream Stream=NULL; Try { //to create a FtpWebRequest object from a URIReqftp = (ftpwebrequest) ftpwebrequest.create (NewUri (string. Format (@"{0}{1}", Ftppath, FileName)); //provide verification of account passwordReqftp.credentials =NewNetworkCredential (userId, PWD); //The default is true to not close the FTP connection after the upload is completeReqftp.keepalive =false; //perform a delete operationReqftp.method =WebRequestMethods.Ftp.DeleteFile; Respose=(FtpWebResponse) reqftp.getresponse (); } Catch(Exception ex) {Sret=Ex. Message; } finally { //close connection and flow if(Respose! =NULL) Respose.close (); if(LocalFile! =NULL) LocalFile. Close (); if(Stream! =NULL) stream. Close (); } //return to execution status returnSret; }
It's not hard to see that the code used to delete is a lot less than uploading and downloading, which means it's easier than the previous two features. Although simple but equally important, the operation of the FTP file will generally appear at the same time, with the completion of a series of work, after the blog will continue to update, please pay attention!
Delete file for FTP file operation