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