List of Get files for FTP file operation

Source: Internet
Author: User
Tags ftp file

The previous introduction of the FTP file operation, and today we will introduce a file to get a list of functions. This function should be the simplest one, it just gets the file information, but not the actual data transfer.

Here is the core code for this feature:

/// <summary>         ///get a list of files/// </summary>         /// <param name= "Ftpserverip" >Server Address</param>         /// <param name= "Ftpuserid" >FTP user name</param>         /// <param name= "FTPPassword" >ftp Password</param>         /// <returns></returns>  Public string[] Getfilelist (stringFtpserverip,stringFtpuserid,stringFTPPassword) {             string[] downloadfiles; StringBuilder result=NewStringBuilder ();             FtpWebRequest reqftp; Try             {                 //to create a FtpWebRequest object from a URIReqftp = (ftpwebrequest) ftpwebrequest.create (NewUri (Ftpserverip)); //specifying data Transfer TypesReqftp.usebinary =true; //FTP user name and passwordReqftp.credentials =NewNetworkCredential (Ftpuserid, FTPPassword); //specify what commands to executeReqftp.method =WebRequestMethods.Ftp.ListDirectory; WebResponse response=Reqftp.getresponse (); //Get file StreamStreamReader reader =NewStreamReader (response.                 GetResponseStream ()); stringline =Reader.                 ReadLine (); //add file names to file list if you have files while(Line! =NULL) {result.                     Append (line); Result. Append ("\ n"); Line=Reader.                 ReadLine (); } result. Remove (result. ToString (). LastIndexOf ('\ n'),1); //Close the streamReader.                 Close (); Response.                 Close (); returnResult. ToString (). Split ('\ n'); }             Catch(Exception ex) {downloadfiles=NULL; returnDownloadfiles; }         }

About the FTP article wrote a few, C # FTP Basic operation is written almost. This blog post should be the last article on C#+ftp.

List of Get files 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.