C # FTP Listfilesonserver

Source: Internet
Author: User

public static bool Listfilesonserver (Uri Serveruri) {//The Serveruri should start with the ftp://scheme.    if (serveruri.scheme! = uri.urischemeftp) {return false;    }//Get the object used to communicate with the server.    FtpWebRequest request = (ftpwebrequest) webrequest.create (Serveruri); Request.    Method = WebRequestMethods.Ftp.ListDirectory;    Get the ServicePoint object used for this request, and limit it to one connection. In a Real-world application your might use the default number of connections (2),//or select a value that works BES    T for your application. ServicePoint sp = Request.    ServicePoint; Console.WriteLine ("ServicePoint connections = {0}.", Sp.    Connectionlimit); Sp.    Connectionlimit = 1; FtpWebResponse response = (ftpwebresponse) request.    GetResponse ();    The following streams is used to read the data returned from the server.    Stream responsestream = null;    StreamReader readstream = null; try {responSestream = Response.         GetResponseStream ();        Readstream = new StreamReader (Responsestream, System.Text.Encoding.UTF8);            if (readstream! = null) {//Display the data received from the server.        Console.WriteLine (Readstream.readtoend ()); } Console.WriteLine ("List Status: {0}", Response.                Statusdescription);        } finally {if (Readstream! = null) {readstream.close (); } if (response! = NULL) {response.        Close (); }} return true;

C # FTP Listfilesonserver

Related Article

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.