Delete file for FTP file operation

Source: Internet
Author: User
Tags ftp connection ftp file

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.