|
C# 2008 Programmer's ReferenceCreate() takes in a URI parameter (containing the full FTP path). ? Set the command to be sent to the FTP server, using the Method property of the FtpWebRequest object. ? Specify the login credential to the FTP server, using the NetWorkCredential class. ? Obtain the response from the FTP server, using the GetResponse() method from the FtpWebRequest class. The PerformWebRequest() function returns a FtpWebResponse object. Back in the GetDirectoryListing() function, after the call to PerformWebRequest() returns, you retrieve the stream containing the response data sent by the FTP server, using the GetResponseStream() method from the FtpWebResponse class. You then use a StreamReader object to read the directory listing: //---Get the file/dir listings and return them as a string array--- private string[] GetDirectoryListing(string path) { try { //---get the directory listing--- FtpWebResponse FTPResp = PerformWebRequest( path, WebRequestMethod.ListDirectoryDetails); //---get the stream containing the directory listing--- Stream ftpRespStream = FTPResp.GetResponseStream(); StreamReader reader = new StreamReader(ftpRespStream, System.Text.Encoding.UTF8); //---obtain the result as a string array--- string[] result = reader.ReadToEnd().Split( Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); FTPResp.Close(); return result; } catch (Exception ex) { MessageBox.Show(ex.ToString()); return null; } } The directory listing is split into a string array ...» |
Код для вставки книги в блог HTML
phpBB
текст
|
|