FTP File Upload
FTP File Download
Delete an FTP File
Create directory for FTP File Operations
I have already introduced the use of FTP for upload and download. Next I will share with you the part for deleting files on the FTP server. With upload and download, deletion is essential.
Deleting is easier than uploading and downloading files. You only need to send a DELETE command to the FTP server.
The following is a complete example of the delete function:
/// <Summary> /// Delete files through FTP /// </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 String Deletefile ( String Ftppath, String Userid, String PWD,String Filename ){ String Sret = " Deleted successfully! " ; Ftpwebresponse respose = Null ; Ftpwebrequest reqftp = Null ; Stream localfile = Null ; Stream = Null ; Try { // Create an ftpwebrequest object based on Uri Reqftp = (ftpwebrequest) ftpwebrequest. Create ( New Uri ( String . Format ( @" {0} {1} " , Ftppath, filename ))); // Provide account and password verification Reqftp. Credentials =New Networkcredential (userid, PWD ); // The default value "true" indicates that the FTP connection is not closed after the upload. Reqftp. keepalive = False ; // Delete Reqftp. method = Webrequestmethods. FTP. deletefile; respose = (Ftpwebresponse) reqftp. getresponse ();} Catch (Exception ex) {sret = Ex. Message ;} Finally { // Close connection and stream If (Respose! = Null ) Respose. Close (); If (Localfile! = Null ) Localfile. Close (); If (Stream! = Null ) Stream. Close ();} // Return execution status Return Sret ;}
It is not difficult to find thatCodeThis is much less than upload and download, which means it is simpler than the previous two functions. Although simple but equally important, FTP file operations usually occur at the same time, and work together to complete a series of work, and will continue to be updated in later blogs. Stay tuned!