private static string[] GetFilesToftp(string WildCard, string uriString, string etServer, string etUser, string etPassword) { string ReturnStr = ""; string ftpServer = etServer; string ftpUser = etUser; string ftpPassword = etPassword; FtpWebRequest request = null; WebResponse response = null; Stream responseStream = null; try { request = WebRequest.Create(@uriString + WildCard) as FtpWebRequest; //Specify we are Listing a directory request.Method = WebRequestMethods.Ftp.ListDirectory; request.Credentials = new NetworkCredential(ftpUser, ftpPassword); //Get a reponse //response = request.GetResponse(); response = (FtpWebResponse)request.GetResponse(); responseStream = response.GetResponseStream(); //Convert the response to a string int ch; while ((ch = responseStream.ReadByte()) != -1) ReturnStr = ReturnStr + Convert.ToChar(ch); //split the string by new line string[] sep = { "\r\n" }; string[] Files = ReturnStr.Split(sep, StringSplitOptions.RemoveEmptyEntries); return Files; } catch (WebException wex) { string Message = (wex.Message != null) ? wex.Message.ToString() : ""; if (wex.Message.StartsWith("The remote server returned an error: (550) File unavailable")) { return null; } else if (wex.Message.StartsWith("The remote server returned an error: (530) Not logged in")) { return null; } else { throw wex; } } finally { if (responseStream != null) { responseStream.Flush(); responseStream.Close(); responseStream.Dispose(); } if (response != null) { response.Close(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)